Automating Maven Releases

Automating maven releases should be pretty straightforward in non-interactive mode. A bug in the release plugin made it impossible in my situation. Every time I would provide the release version(s) as command line arguments, the release plugin would choke on me with the following error message:

Error parsing version, cannot determine next version: Unable to parse the version string

The following shellscript works around this problem, by redirecting input to the maven execution.

Note: I’m releasing a project with a parent and 2 child modules, which is why I have to specify three versions ( + 1 SCM tag). If you’re not using multiple modules, or are using more, you’ll have to adjust the script accordingly.

#!/bin/sh

releaseVersion=AmazingRelease1
nextVersion=AmazingRelease2

mvn \
    release:prepare -P production &>> /tmp/build.log << EOS
$releaseVersion
$releaseVersion
$releaseVersion
$releaseVersion
$nextVersion-SNAPSHOT
$nextVersion-SNAPSHOT
$nextVersion-SNAPSHOT
EOS

mvn release:perform -P production &>> /tmp/build.log

This is an abridged version of our full release script. The full version asks the user to enter the release version once, then releases several versions using different profiles and creates a distribution set with all versions and a bunch of documentation. This works in my situation, but if your release procedure is more complicated then you can just expand on the script :-).

One Reply to “Automating Maven Releases”

Leave a Reply

Your email address will not be published. Required fields are marked *