Increment versions with the Maven Build Helper and the Versions Plugin

1 Comment

Today I want to show you a simple way how you can increment the version inside the Maven pom.xml file. When you are using the Maven Release Plugin then it will automatically increment the version after a release and you can stop reading here. But when you are interested in an alternative approach for releasing software with Maven, then go further and read first this blog entry, where I describe it in more detail. For all those who want to automate also the version increment step, they should have a look on a secret feature of the Maven Build Helper Plugin. The Goal “build-helper:parse-version” provides not only the fragments of the actual version in the pom.xml, it calculates also the incremented fragments of the version:


To increment the last fragment of the version from e.g. 1.0.0 to 1.0.1 you can simply do that:

mvn build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.nextIncrementalVersion} versions:commit

The first goal “build-helper:parse-version” provides the above fragments as properties and the second goal “versions:set” writes the new version into the pom.xml and creates also a backup of the old pom.xml. The last optional goal “versions:commit” removes this backup file if you want.

The documentation doesn’t say anything about those properties, but you can see it here in the code. I tried some other approaches, but for me this is the simplest way to do that. What are your preferred ways to release your software with Maven?



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