Passing arguments to Maven release build

Puce picture Puce · Apr 15, 2013 · Viewed 30.2k times · Source

I'm trying to release a library using Maven and perform a site-deploy to sourceforge (I have create an interactive shell first). The release is done by a Jenkins job (using the Maven Release Plugin for Jenkins).

I tried:

-X -e -Dresume=false -Dusername=puce release:prepare release:perform -Darguments="-Dusername=puce"

and

-X -e -Dresume=false -Dusername=puce -Darguments=-Dusername=puce release:prepare release:perform

but both times the job hangs at site:deploy of the first module:

 [INFO] --- maven-site-plugin:3.2:deploy (default-deploy) @ myproject-parent ---
 [INFO] Parent project loaded from repository: myGroupId:myOtherproject-parent:pom:1.0
 [INFO] Parent project loaded from repository: myGroupId:myOtherproject-parent:pom:1.0
 Using private key: /opt/jenkins/.ssh/id_dsa

When I stop the job, the following gets printed at end:

Password for ${username}@shell.sourceforge.net: channel stopped

which probably means that ${username} wasn't resolved.

How can I resolve the ${username}?

Edit:

Note that the following runs fine:

site-deploy -Psonatype-oss-release -Dusername=puce

Edit 2: As part of release:perform maven executes the following command:

/usr/share/maven/bin/mvn -s /tmp/release-settings7797889802430474959.xml deploy site-deploy --no-plugin-updates --batch-mode -Psonatype-oss-release -P nexus -f pom.xml

-Dusername=puce doesn't seem to get passed to this maven command...

Also note that help:effective-pom shows the following maven-release-plugin configuration:

<plugin>
  <artifactId>maven-release-plugin</artifactId>
  <version>2.2.2</version>
  <configuration>
    <mavenExecutorId>forked-path</mavenExecutorId>
    <useReleaseProfile>false</useReleaseProfile>
    <arguments>-Psonatype-oss-release</arguments>
  </configuration>
</plugin>

So 'arguments' gets defined and its value seems to reach the embedded maven command instead of the value passed on the command line...

Answer

Sander Verhagen picture Sander Verhagen · Apr 15, 2013

What I've successfully done in the past is as follows:

  • Define a property in the POM file, e.g.:

    <properties>
        <release.arguments></release.arguments>
    </properties>
    
  • Add the POM property to the plugin configuration in the POM file, e.g.;

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-release-plugin</artifactId>
        <configuration>
            <arguments>${release.arguments}</arguments>
           ...
    
  • Pass the argument through the property on the command-line, e.g.:

    mvn release:prepare -Drelease.arguments="-N -Prelease"
    

Hope this helps.