Maven: How to deploy with deploy-file and custom wagon
Asked Answered
P

4

9

I'm trying to use a custom maven wagon extension to deploy a jar to my own repository. Can I somehow configure in settings.xml that it recognizes the custom url scheme to be used with the specific wagon or do I have to always modify pom files to contain the wagon extension?


There doesn't need to be a base pom or any pom available when using the deploy-file. Settings.xml is the only place which is guaranteed to be there, but I can't figure out how to use it to define extensions.

Peary answered 2/3, 2009 at 14:24 Comment(0)
P
5

OK, ok, a correction: you cannot define the <build> element inside a <profile> defined in settings.xml. You could activate the profile in settings.xml, but define it in your base-pom.

Sorry, the only other way I could think of (probably what are you looking for), is to copy the extension jar directly under $M2_HOME/lib. All $M2_HOME/lib/*.jar are put in the classpath, so this must virtually have the same effect as an <extension>.

The extension however is better, because you can more easily control which version of the extension is used (e.g. trough the base-pom).

OK just try copying the extension jar under

    $M2_HOME/lib
Putrescible answered 6/3, 2009 at 10:33 Comment(4)
Yeah but how do I define the extension in local settings?Peary
Where did you find that it should work as my maven complains about "build" inside a "profile"?Peary
ok, sorry, see my correction - the profile definitions in settings.xml are somehow limited. User $M2_HOME/libPutrescible
This is what I'm doing currently, but it's not very handy as everyone using the extension have to manually download it and place it in the lib directory. Thanks you anyway!Peary
S
6

I don't know if the comment above by Brian Fox is still valid in 2013. But in the end I had to create a minimal pom.xml in the directory where I tried to upload the artifact to enable the wagon build extension.

I had to add groupId, artifactId and version to the pom.xml so that Maven would not complain although I provided them to the deploy-file goal on the commandline (I guess deploy-file would only care about the commandline parameters though):

<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion>
<groupId>your-groupId</groupId>
<artifactId>your-artifactId</artifactId>
<version>your-version</version>
<build>
  <extensions>
    <extension>
      <groupId>org.apache.maven.wagon</groupId>
      <artifactId>wagon-ssh</artifactId>
      <version>2.4</version>
    </extension>
  </extensions>
</build>
</project>

With this simple "pom.xml" in place I could execute the deploy-file finally using scp as the protocol:

mvn deploy:deploy-file -Durl=scp://shell.sourceforge.net:/home/project-web/... -DrepositoryId=repoId -Dfile=my-file.jar -DgroupId=your-groupId -DartifactId=your-artifactId -Dversion=your-version -Dpackaging=jar
Scag answered 12/5, 2013 at 23:51 Comment(2)
I can confirm that the project, group, artifact, and version is ignored in favor of the command-line params. Good find!Sophistication
Follow this guide and you dont need the pom file: github.com/dwburns/s3-maven-wagonOrgell
P
5

OK, ok, a correction: you cannot define the <build> element inside a <profile> defined in settings.xml. You could activate the profile in settings.xml, but define it in your base-pom.

Sorry, the only other way I could think of (probably what are you looking for), is to copy the extension jar directly under $M2_HOME/lib. All $M2_HOME/lib/*.jar are put in the classpath, so this must virtually have the same effect as an <extension>.

The extension however is better, because you can more easily control which version of the extension is used (e.g. trough the base-pom).

OK just try copying the extension jar under

    $M2_HOME/lib
Putrescible answered 6/3, 2009 at 10:33 Comment(4)
Yeah but how do I define the extension in local settings?Peary
Where did you find that it should work as my maven complains about "build" inside a "profile"?Peary
ok, sorry, see my correction - the profile definitions in settings.xml are somehow limited. User $M2_HOME/libPutrescible
This is what I'm doing currently, but it's not very handy as everyone using the extension have to manually download it and place it in the lib directory. Thanks you anyway!Peary
A
2

You need to add the wagon extension to your top level pom.xml. Most environments have a corporate one at the top of all their projects (best practice), so this generally isn't too painful for individual developers -- they just inherit from the corporate pom.

<build>
  <extensions>
    <extension>
      <groupId>org.apache.maven.wagon</groupId>
      <artifactId>wagon-scm</artifactId>
      <version>1.0-alpha-7-SNAPSHOT</version>
    </extension>
    <extension>
      <groupId>org.apache.maven.scm</groupId>
      <artifactId>maven-scm-manager-plexus</artifactId>
      <version>1.0-beta-3-SNAPSHOT</version>
    </extension>
    <extension>
      <groupId>org.apache.maven.scm</groupId>
      <artifactId>maven-scm-provider-svnexe</artifactId>
      <version>1.0-beta-3-SNAPSHOT</version>
    </extension>
  </extensions>
</build>
<distributionManagement>
  <site>
    <id>my.svn.server</id>
    <url>scm:svn:https://[email protected]/svn/root/module</url>
  </site>
</distributionManagement>

When you register your provider, it also registers the protocol pattern as well I believe. You can see a full list of the existing providers here.

I believe it is the getScmType() method that registers the extension, but I'm not 100% certain.

/** {@inheritDoc} */
public String getScmType()
{
    return "git";
}

The link to the Git provider's source can be found here.

Alessandraalessandria answered 6/3, 2009 at 14:52 Comment(3)
Developers shouldn't have to have any poms available when using the deploy-file feature. How do I use settings to define extensions?Peary
I have a feeling you are chasing something that oddly can't be done. I'd try asking the #Maven IRC channel too. I agree; developers shouldn't have to have a pom for deploy-file. Can't do extensions in settings.xml. Surprised even me!Alessandraalessandria
You can't unless you define a pom. It's just not a supported use case at the moment.Kakalina
P
2

siddhadev is right, but there are few additional things... (I'd put this in a comment but I don't have enough reputation)

You can keep your JARs cleanly separated by putting them under: $M2_HOME/lib/ext

You need all of the dependencies, so do something like:

  1. cd ~/.m2/repository/org/apache/maven/wagon/wagon-ssh-external/2.2
  2. cp wagon-ssh-external-2.2.jar $M2_HOME/lib/ext
  3. cp wagon-ssh-external-2.2.pom pom.xml
  4. mvn dependency:copy-dependencies -DoutputDirectory=$M2_HOME/lib/ext
Prather answered 11/5, 2012 at 19:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.