Last Updated: February 25, 2016
·
4.77K
· bjpbakker

Maven release plugin (-D) arguments

Today I had a bit of trouble releasing a Maven project through a continuous integration build. The problem was that our build needs a PhantomJS executable. The executable is not on the PATH of the CI agent.

Thus the executable must be passed as a Java system property. For regular builds running the following maven command works just fine.

mvn clean verify -Dphantomjs.binary.path=/path/to/phantomjs

The problem with the maven release plugin is that it forks a maven build to run goals clean through verify, and that any properties passed to maven are not passed on to the forked process.

Luckily there is a way to specify the arguments to pass on to the forked process. Because this is not really clear from the documentation, I choose to share it in this tip.

To pass on arguments to the forked process you must specify them with the arguments system property.

So to make the maven release preparation goal pass the phantomjs path to the forked process, I use the following command.

mvn release:prepare -Darguments=-Dphantomjs.binary.path=/opt/phantomjs/current/bin/phantomjs