Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven 3: deploying an artifact using SCP

Tags:

scp

maven

As far as I can tell, deploying a third-party binary artifact using maven is done like so:

mvn deploy:deploy-file -DgroupId=<group-id> \
  -DartifactId=<artifact-id> \
  -Dversion=<version> \
  -Dpackaging=<type-of-packaging> \
  -Dfile=<path-to-file> \
  -DrepositoryId=<id-to-map-on-server-section-of-settings.xml> \
  -Durl=<url-of-the-repository-to-deploy>

Suppose that my repository is accessible using scp, so for instance in the above command

-Durl=scpexe://example.org//users/mvnrepo/maven

Using maven 3, this deployment command fails with an error message.

The workaround I used was to copy two jars: wagon-ssh-common-2.2.jar and wagon-ssh-external1.0.jar to my $M2_HOME/lib directory.

Hence my question: Why is it that Maven cannot retrieve the appropriate wagons by itself?

(and, how to have it do that if it is possible?)

like image 568
Rom1 Avatar asked Jul 10 '12 08:07

Rom1


2 Answers

Wagons are Maven extensions. You can add them as follows:

<project>
    <build>
        <extensions>
            <extension>
                <groupId>org.apache.maven.wagon</groupId>
                <artifactId>wagon-ssh</artifactId>
                <version>1.0</version>
            </extension>
        </extensions>
    </build>
</project>

For more details you can check the Maven Wagon page.

like image 118
carlspring Avatar answered Oct 02 '22 00:10

carlspring


As a straight and short answer : adding a third party require that you have :

  • either a Maven Repository (app like Nexus or Artifactory with GUI)
  • or a pom.xml (in command line)

Further Considerations

I assume you want to use a third party library, not just publishing you own one.

  1. If you want to use a third party library, you really should look for an existing repository hosting it. I'm pretty sure you have already searched, but it's the better way to do it. If you find one, just add it to your maven repo cache.

  2. Next, if you don't find one, you can add it to your own repo, assuming you HAVE on. I don't really know if you are familiar with this, and it may sound obvious, so please forgive me. but A repository is not only a file server. Carlspring kinldy talked about Nexus in order to give an example. There is also Artifactory, and many others. They are true app servers. So, you must have your own one. They have interfaces that allow you to add artifacts, providing some information about it (at least group, id, version).

  3. Finally, Maven deals with dependency paradigm. This is not a formal, but just pieces of consideration :

    • who developed it ?
    • what it depends on (other libs) ?
    • who provide it ?
    • is it trustable ?
    • ...

All those informations should be placed in pom.xml, and they would really be placed by the author (see 1), or at least provided when you use it in Maven (see 2). In all cases, they come from pom.xml ... auto generated or not ... so you'll need a pom.xml :).


Indeed, publishing or using libraries leads to the same problems : you must provide information about what the you dev in order to be used in the more automatted and trustable manner. It's sometimes quite ugly, but this is the better way to do it.

Once again, please forgive me if that sounds obvious. But by experience, when you don't manage to do something with Maven, it's quite often because it's not the good way to do it, even your process is very very smaller than "The Greatest Developpement Process" that should drive every one :)

like image 24
Jean-Rémy Revy Avatar answered Oct 01 '22 22:10

Jean-Rémy Revy