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.
Updating version numbers of modules in a multi-module Maven project where the aggregate root isn't a parent pom
Recently (23/09/2017) a documentation was added to Versions Maven Plugin. In order to update all project under aggregate project you need to add supplemental command line parameters:
mvn versions:set -DnewVersion=0.0.1 -DoldVersion=* -DgroupId=* -DartifactId=*
This is needed otherwise the filter for the versions (via -DoldVersion=) would have filtered out that module cause it has a different version than the rest of modules. Furthermore you need to add the -DgroupId= and -DartifactId=* otherwise the module-1 will also filtered out based on the differences in groupId and artifactId.
Convenient way to update version of multi-module project in Eclipse
Following the idea of https://stackoverflow.com/a/34091470/927493,
I configured the newVersion
parameter to be ${string_prompt:newVersion}
as shown in the image below
Then I get prompted for the version number which works fine.
What is the best stategy to update modules version in multi-module Maven project
Personally I will go absolutely for your strategy 1. That's the strategy is used in a company I work for. Your side effect that you mention as HDD space or upgrading module versions which are not required to be upgraded are minor issues compares to "versions zoo".
Only I will vote for your strategy number 2 in cases that you are using OSGI architecture and this requires very precise module versionning strategy, and if you upgrade all the version at once, it will ruin the big benefict of OSGI (hot-deploy only the modules/submodules which require to be updated).
I also suggest you to have a look on http://java.dzone.com/articles/why-i-never-use-maven-release which gives good hints how to upgrade version in multi module maven project, and also how to tracked in any CVS
Updating the versions in a Maven multi-module project
You may have more luck with the release plugin but it may require some tweaking
versions:set
is designed to update the version of the pom that it executes against... ie the root of the reactor.
If you follow it's conventions, then it will work... But you need to know its conventions.
When you have /project/parent/version
and /project/version
both specified but "accidentally" at the same value, the versions plugin assumes that the two versions are just accidentally the same, and so does not update the child project's version when the parent version is being updated. updateMatchingVersions
tells the plugin to assume that it us not an accident and that the child should be in lock step.
If you only specify /project/parent/version
and leave the project version unspecified, therefore relying on inheritance, the plugin will add the child project to the list of version changes (and hence loop through all the projects again to ensure it catches any additional required changes)
The versions plugin does not currently provide an option to force everything to the one version... Though that might be a good idea.
You can get what you want with three commands, eg
mvn versions:set -DnewVersion=...
cd projectA
mvn versions:set -DnewVersion=...
cd ../projectB
mvn versions:set -DnewVersion=...
This is because versions:set
will attempt to "grow" the reactor if the parent directory contains an aggregator pom that references the invoked project...
In other words when you have a reactor with no common parent, versions assumes that the common version number is by accident, but it will pick up the intent from the wider reactor
Fastest way to update the version number in Maven of all projects and modules in IntelliJ
When I need to bump the same version in multiple poms at once in my project, I always use the "replace in path" action.
Tip: you can use the Help -> Keymap Reference
menu to quickly find the shortcut or use the Find Action
action and type "replace in path".
Just be careful you don't replace any unwanted versions of a dependency that has the same version by coincidence.
In the "replace in path" window you can select "open in find window" and select there which occurrences you wish to include/exclude from the replace action.
Building a multi module maven project with Skaffold and Jib
When you specify a project:
, Skaffold will invoke something like:
mvn --projects com.example:my-project-main-module --also-make jib:build
This will be executed from the context directory. The --also-make
causes Maven to rebuild any dependencies (like your lib-module
) as necessary.
Make sure you can run the command-line above separately from Skaffold. Check that your lib-module
is included as a <module>
in your top-level pom.xml
, and that your main-module
has a <dependency>
to your lib-module
.
Related Topics
Integer.Valueof() VS. Integer.Parseint()
How to Manage Exceptions Thrown in Filters in Spring
How to Build Sources Jar with Gradle
Java Linkedhashmap Get First or Last Entry
Stand-Alone Java Code Formatter/Beautifier/Pretty Printer
Gradle: Could Not Determine Java Version from '11.0.2'
Lambda Expression to Convert Array/List of String to Array/List of Integers
Why Can't I Declare Static Methods in an Interface
Synchronization of Non-Final Field
Spring Boot Multiple Datasource
How to Change an Eclipse Default Project into a Java Project
Java Arraylist - How to Tell If Two Lists Are Equal, Order Not Mattering
Differencebetween Closeablehttpclient and Httpclient in Apache Httpclient API