Thursday, January 09, 2014

Passing command line parameters to the maven release plugin

Today I re-learnt some things:

Passing command line parameters to the maven release plugin

When using the maven release plugin, e.g. with "release:prepare", the plugin will run a subprocess "mvn clean verify --no-plugin-updates" on the project. This will not pass any arguments that you specified to maven, example:
mvn -Pthis-profile -Duse.property=that release:clean release:prepare release:perform
will not pass those parameters to the subprocess. You need to define them with -Darguments to pass them, like:
mvn "-Darguments=-Pthis-profile -Duse.property=that" release:clean release:prepare release:perform 
See http://maven.apache.org/maven-release/maven-release-plugin/prepare-mojo.html#arguments

Why doesn't it work for me? Parent pom overwrite?

Note that if you use parent poms, they (or their ancestors) may specify the <arguments> configuration for the maven release plugin and passing in parameters via -Darguments will stop working.
<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-release-plugin</artifactId>
   ...
   <configuration>
      <arguments>-Dmy.property=this</arguments>
      ...
   </configuration>
</plugin>
the correct way would have been to define it like that:
      <arguments>-Dmy.property=this ${arguments}</arguments>
so that -Darguments would continue to work. If you find this, you can either change the parent pom or overwrite the configuration again in your project pom to allow -Darguments to work.

Passing multiple properties and shell escaping

When passing multiple arguments via the -Darguments method, the mind may logically use something like:
-Darguments='-Pthis-profile -Duse.property=that'
however this is not proper shell escaping, and the properties may not be passed correctly (you might end up passing a profile name of "this-profile -Duse.property=that"). You want:
"-Darguments=-Pthis-profile -Duse.property=that"

Proper googling

When you want to find information on -Darguments on maven, searching "maven -Darguments" is probably what you'll first search, but hold on -- search syntax means that will search for "maven" and - yes - omit all results with "Dargument" (which are probably the results you want). "maven Darguments" did the trick instead.



4 comments:

Unknown said...

this helped me for our issue. Very nicely shared the learning and wisdom. Thanks buddy.

mikey said...

This saved me today! Thanks a million mate, really appreciated.

Mark Bamberg said...

Thank you for taking the time to document this. It was not at all obvious the the quotes proceed the -Darguments and enclose multiple arguments. Very well explained. I spent half a day struggling to find the solution

dilino said...

Thanks, that helped me a lot. Great work!