Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing arguments to Maven release build

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...

like image 653
Puce Avatar asked Apr 14 '13 23:04

Puce


People also ask

How do you pass variables in POM xml?

To refer to environment variables from the pom. xml, we can use the ${env. VARIABLE_NAME} syntax. We should remember to pass the Java version information via environment variables.

Which property value arguments are passed to Maven POM xml?

Maven will use the value (2.5) passed as an argument to replace the COMMON_VERSION_CMD property set in our pom. xml. This is not limited to the package command — we can pass arguments together with any Maven command, such as install, test, or build.

What is Release Candidate in Maven?

Release Candidate (RC) is the build released internally to check if any critical problems have gone undetected into the code during the previous development period. Release candidates are NOT for production deployment, but they are for testing purposes only.


2 Answers

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.

like image 75
Sander Verhagen Avatar answered Sep 23 '22 12:09

Sander Verhagen


Overriding

<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>

with

    <plugin>
        <artifactId>maven-release-plugin</artifactId>
        <configuration>
            <mavenExecutorId>forked-path</mavenExecutorId>
            <useReleaseProfile>false</useReleaseProfile>
            <arguments>-Psonatype-oss-release -Dusername=${username}</arguments>
        </configuration>
    </plugin>

in one of the parents did the trick.

It seems to be a bug that the value on the command line doesn't override the value in the POM.

like image 20
Puce Avatar answered Sep 22 '22 12:09

Puce