Beliebte Suchanfragen

Cloud Native

DevOps

IT-Security

Agile Methoden

Java

//

Increment versions with the Maven Build Helper and the Versions Plugin

5.4.2015 | 1 minutes of reading time

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:

parsedVersion.nextMajorVersion parsedVersion.nextMinorVersion parsedVersion.nextIncrementalVersion

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?

share post

Likes

2

//

More articles in this subject area

Discover exciting further topics and let the codecentric world inspire you.

//

Gemeinsam bessere Projekte umsetzen.

Wir helfen deinem Unternehmen.

Du stehst vor einer großen IT-Herausforderung? Wir sorgen für eine maßgeschneiderte Unterstützung. Informiere dich jetzt.

Hilf uns, noch besser zu werden.

Wir sind immer auf der Suche nach neuen Talenten. Auch für dich ist die passende Stelle dabei.