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.

Rich Seller
  • 83,208
  • 23
  • 172
  • 177
JtR
  • 20,568
  • 17
  • 46
  • 60

4 Answers4

5

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
Community
  • 1
  • 1
void256
  • 1,286
  • 10
  • 11
  • I can confirm that the project, group, artifact, and version is ignored in favor of the command-line params. Good find! – GuyPaddock Apr 12 '17 at 03:57
  • Follow this guide and you dont need the pom file: https://github.com/dwburns/s3-maven-wagon – JARC Apr 10 '18 at 13:35
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
siddhadev
  • 16,501
  • 2
  • 28
  • 35
  • Yeah but how do I define the extension in local settings? – JtR Mar 10 '09 at 12:52
  • Where did you find that it should work as my maven complains about "build" inside a "profile"? – JtR Mar 10 '09 at 18:30
  • ok, sorry, see my correction - the profile definitions in settings.xml are somehow limited. User $M2_HOME/lib – siddhadev Mar 10 '09 at 19:03
  • 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! – JtR Mar 10 '09 at 19:22
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
Arlo
  • 1,331
  • 2
  • 15
  • 26
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://username@svn.apache.org/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.

Matthew McCullough
  • 17,160
  • 7
  • 39
  • 38
  • 1
    Developers shouldn't have to have any poms available when using the deploy-file feature. How do I use settings to define extensions? – JtR Mar 10 '09 at 12:53
  • 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! – Matthew McCullough Mar 10 '09 at 21:58
  • 1
    You can't unless you define a pom. It's just not a supported use case at the moment. – Brian Fox May 08 '09 at 21:57