Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven multi-module project version management [duplicate]

Tags:

What is the best practice for specifying version of a multimodule maven project?

I would like to have one version string across all modules. Even if I can have only one version definition in the root parent pom, I need to specify the parent pom version in each pom's. Which means, if I need to change version, I need to change all poms. Practically defeats the purpose. Any ideas??

like image 224
anoopelias Avatar asked Jun 26 '13 06:06

anoopelias


People also ask

What are the advantages of multi-module Maven project?

One more module, another webapp created as the result of the maven build with no special tinkering. Business logic is shared easily between webapp and rest-webapp and I can deploy them as needed.

What is Maven Multi-Module project?

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.

Can two Maven modules depend on each other?

Because modules within a multi-module build can depend on each other, it is important that the reactor sorts all the projects in a way that guarantees any project is built before it is required. The following relationships are honoured when sorting projects: a project dependency on another module in the build.

How can I add an existing Maven project to another Maven project as a module?

Just do a regular "Import existing maven project into workspace" to get this done. Show activity on this post. If you use M2e with Eclipse you do not need to do that, because Eclipse resolves dependencies across the workspace. You just need to have the two projects open and your dependencies declared correctly.


2 Answers

Have you tried the versions-maven plugin ?

with mvn versions:set -DnewVersion="1.1-SNAPSHOT" you are able to set in all underlying maven projects the given version.

Afterwards you have to do a mvn versions:commit to remove temporary files and commit to your VCS

like image 130
smsnheck Avatar answered Oct 07 '22 19:10

smsnheck


The better way is define your version in parent pom.xml as follows.

<groupId>com.my.code</groupId> <artifactId>my_pro</artifactId> <version>${YOUR_VERSION}</version>  <properties>     <JDK_VERSION>1.7</JDK_VERSION>             <YOUR_VERSION>1.0-SNAPSHOT</YOUR_VERSION>// here you define your version     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>     <org.springframework.version>3.1.2.RELEASE</org.springframework.version> </properties> 

Then you don't want to change your version number one by one in all child pom.xml.

child pom.xml can add dependency as follows

<version>${YOUR_VERSION}</version> 
like image 30
Ruchira Gayan Ranaweera Avatar answered Oct 07 '22 17:10

Ruchira Gayan Ranaweera