When you have a multi project configuration for your maven based application, manually updating the project version after each release is not that easy. There will be at least 2 references to the project version number and it will give unexpected error if you forget to update version for one child project dependency.
We can update the version number easily by using below command.
mvn build-helper:parse-version versions:set-DnewVersion=${parsedVersion.majorVersion).$(parsedVersion.minorVersion}.$(parsedVersion.nextIncrementalVersion}-${parsedVersion qualifier} -DgenerateBackupPoms=false
Above command will work only if your project version is in
MAJOR.MINOR.INCREMENTAL-QUALIFIER
format. e.g.,0.0.1-SNAPSHOT
.
If your project version doesn’t contain qualifier (e.g., 0.0.1
), use below command.
mvn build-helper:parse-version versions:set-DnewVersion=${parsedVersion.majorVersion).$(parsedVersion.minorVersion}.$(parsedVersion.nextIncrementalVersion} -DgenerateBackupPoms=false
Use of scripts from command prompt
Typing this long command all the time is not easy and it is a good idea to store this as a DOS/UNIX script. If you are using windows OS, make sure you have a bin folder configured in your system. If not already done, refer https://sastrija.com/configuring-bin-folder-in-windows-os/ for more details. In my case, I’ve saved this script as update.bat
in my Windows system.
Once the script is created, open the parent project folder in command prompt and enter update command
. This will update the version in all pom.xml
files for the project.
Use of script from Eclipse/STS
Running this command from Eclipse/STS is more easy.
- Right click parent project from Project Explorer and select
Show In
>Terminal
- Type update and enter. This will update the version in all
pom.xml
. Here I assume you have named the script name asupdate.bat
.