Updating version numbers of modules in a multi-module Maven project
Use versions:set
from the versions-maven plugin:
mvn versions:set -DnewVersion=2.50.1-SNAPSHOT
It will adjust all pom versions, parent versions and dependency versions in a multi-module project.
If you made a mistake, do
mvn versions:revert
afterwards, or
mvn versions:commit
if you're happy with the results.
Note: this solution assumes that all modules use the aggregate pom as parent pom also, a scenario that was considered standard at the time of this answer. If that is not the case, go for Garret Wilson's answer.
You may want to look into Maven release plugin's release:update-versions goal. It will update the parent's version as well as all the modules under it.
Update: Please note that the above is the release plugin. If you are not releasing, you may want to use versions:set
mvn versions:set -DnewVersion=1.2.3-SNAPSHOT
The given answer assumes that the project in question use project inheritance in addition to module aggregation. In fact those are distinct concepts:
https://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Project_Inheritance_vs_Project_Aggregation
Some projects may be an aggregation of modules, yet not have a parent-child relationship between aggregator POM and the aggregated modules. (There may be no parent-child relationship at all, or the child modules may use a separate POM altogether as the "parent".) In these situations the given answer will not work.
After much reading and experimentation, it turns out there is a way to use the Versions Maven Plugin to update not only the aggregator POM but also all aggregated modules as well; it is the processAllModules
option. The following command must be done in the directory of the aggregator project:
mvn versions:set -DnewVersion=2.50.1-SNAPSHOT -DprocessAllModules
The Versions Maven Plugin will not only update the versions of all contained modules, it will also update inter-module dependencies!!!! This is a huge win and will save a lot of time and prevent all sorts of problems.
Of course don't forget to commit the changes in all modules, which you can also do with the same switch:
mvn versions:commit -DprocessAllModules
You may decide to dispense with the backup POMS altogether and do everything in one command:
mvn versions:set -DnewVersion=2.50.1-SNAPSHOT -DprocessAllModules -DgenerateBackupPoms=false
If you want to fully automate the process (i.e. you want to increment the version number without having to know what the current version number is), you can do this:
mvn build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.nextIncrementalVersion} versions:commit