Reputation: 468
I have a multi-module project.
The parent project contains no code, just sets common property definitions, project version numbers, etc. And specifies the modules and build order.
I'd like each sub module to have a
<parent>
<relpath>../pom.xml</relpath>
</parent>
So each module inherits the group, version, and common properties such as java compiler version, etc.
But this doesn't seem to be valid maven. I have to specify the parent group, artifact, and version. (instead of just artifactID).
When I bump the version of the project, I have to go into each submodule to bump the version of the parent.
I'd rather not have to keep track that submodule A version X is compatible with submodule B version Y... I'd like all submodules (A..Z) to have a new version that matches the project (parent.)
Is this possible?
Upvotes: 0
Views: 146
Reputation: 4221
Yes, it is possible, but you need to use a third-party plugin, namely the Versions plugin from Mojo/Codehaus. You don't need to install or do anything in particular to use it, but it isn't part of the core plugins.
Let's say you have the following layout:
Root POM:
<project>
<groupId>org.example</groupId>
<artifactId>root-pom</artifactId>
<version>1.0.0-SNAPSHOT</version>
<modules>
<module>child-1</module>
...
</modules>
...
</project>
Child POM(s), located directly in a sub-directory to the root POM, with intra-dependencies:
<project>
<parent>
<groupId>org.example</groupId>
<artifactId>root-pom</artifactId>
<version>1.0.0-SNAPSHOT</version> <!-- Hard-coded -->
<relativePath>..</relativePath>
</parent>
<artifactId>child-1</artifactId>
...
<dependencies>
<dependency>
<groupId>org.example</groupId>
<artifactId>child-2</artifactId>
<version>${project.version}</version> <!-- Dependency to another module in the reactor -->
</dependency>
</project>
Now, if you have lots of child modules, you can use this command to keep your reactor coherent:
mvn versions:set versions:commit -DnewVersion=1.1.0-SNAPSHOT
This will transform all your POMs to version 1.1.0-SNAPSHOT
(or whatever you choose) so that the parent version in the child poms is the same as the root POM. Coincidently, this is the same approach employed by the release plugin during mvn release:prepare
.
Upvotes: 1