Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating version numbers of modules in a multi-module Maven project

Tags:

maven

I have a multi-module maven project. We intend to version all these modules together. But as of now I am ending up hard-coding version in each of the module pom.xml as below

<parent>     <artifactId>xyz-application</artifactId>     <groupId>com.xyz</groupId>     <version>2.50.0.g</version> </parent> <modelVersion>4.0.0</modelVersion> <groupId>com.xyz</groupId> <artifactId>xyz-Library</artifactId> <version>2.50.0.g</version> 

and the main parent module has the below configuration

<modelVersion>4.0.0</modelVersion> <groupId>com.xyz</groupId> <artifactId>xyz-application</artifactId> <version>2.50.0.g</version> <packaging>pom</packaging> 
like image 475
sandeepkunkunuru Avatar asked Apr 20 '11 06:04

sandeepkunkunuru


People also ask

What does Mvn versions commit do?

Description: Removes the initial backup of the pom, thereby accepting the changes.

How do I change my Maven version?

Setting the Maven versionAdd an environment variable to your development system called ATLAS_MVN. Set the value of ATLAS_MVN to your Maven executable. Keep in mind this should be the Maven executable, not the Maven home. Verify the configuration by running the atlas-version command.

What is multi-module project in Maven?

A multi-module project is built from an aggregator POM that manages a group of submodules. In most cases, the aggregator is located in the project's root directory and must have packaging of type pom. The submodules are regular Maven projects, and they can be built separately or through the aggregator POM.


1 Answers

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.

like image 160
Sean Patrick Floyd Avatar answered Oct 19 '22 08:10

Sean Patrick Floyd