Dark theme | Light theme

July 16, 2008

Passing -D arguments along to the release plugin in Maven

The Maven release plugin is very useful to make a release of our projects. A lot of things are done for us, like tagging the source code in our Source Control Management (SCM). During the process the project is build again with the following command: mvn clean verify --no-plugin-updates. This will build the project again with all small changes already done by the Maven release plugin.

Now suppose we want to run the release plugin with a explicit profile from the command line. For example we execute mvn release:prepare -Pproduction to create a release and get the result we can copy to a production environment. The release plugin will add our -Pproduction to command to build the project. So the plugin executes mvn clean verify --no-plugin-updates -Pproduction. Great! No worries it just happens.

But what happens with Java system properties we add to our commandline? Unfortunately they will not be included by the release plugin. For example if we invoke mvn release:prepare -DmyProp=value, then the release plugin will only run mvn clean verify --no-plugin-updates. But there is a way to pass our property along to the release plugin. We must use -Darguments and then specify our extra arguments. In our example we have to run mvn release:prepare -Darguments=-DmyProp=value and then the complete command from the release plugin will be mvn clean verify --no-plugin-updates -DmyProp=value.