Maven versioning of multi-module projects with parent POM
maven
Solution
If you have a structure like the following:
root
+-- pom.xml (1.0-SNAPSHOT)
!
+-- module1
! +-- pom.xml (1.0-SNAPSHOT)
+-- module2
+-- pom.xml (1.0-SNAPSHOT)
all modules (module1 and module2) using root as their parent like this:
<parent>
<groupId>xxx</groupId>
<artifactId>xxx</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
If you want to factor out other default setup like pluginManagement or dependencyManagement for other projects as well you have to use a separate parent pom which must be a separate maven project which contains only the pom.xml. Furthermore this project will be deployed and released separately. If you do so you can use this as parent in the root pom of the above structure.
If you like to make a release you will go simply into the root folder of the above structure and the version number etc. will automatically incremented.
mvn -B release:prepare release:perform
Problem
This is a slightly different version of this previous question, in that I have separate multi-module and parent POMs: In a Maven project, how can I automatically update the version all child modules, plus the parent? I am trying to update my POMs to go from a development snapshot version to a released version number. I have googled the issue to death, tried the release and version plug-in, and nothing seems to be able to handle my fairly simple setup. Following published Maven best practices, and trying not to duplicate information when I can avoid to, I ended up with the structure below for my multi-module project. There is a single version defined by the common pom-parent.xml; and B depends on A. I find it a bit surprising that the standard plug-ins can't handle what seems to be a fairly basic setup, am I missing something? None of the workarounds I have come up with are completely satisfactory: define the product version as a property is a bit flaky, the same module source could get different versions because of a user settings.xml or other trick merge the root pom.xml and pom-parent.xml and move the product-wide build steps I currently maintain in the root pom into a dedicated module; and hope that the std plug-ins will then work... not tried. Any suggestion? root/pom-parent.xml: parent of all the POMs below ``` <project...> <groupId>acme</groupId> <artifactId>ParentPom</artifactId> <packaging>pom</packaging> <version>1.0.0-SNAPSHOT</version> ``` root/pom.xml: multi-module projects with A and B as submodules ``` <project ...> <parent> <groupId>acme</groupId> <artifactId>ParentPom</artifactId> <version>1.0.0-SNAPSHOT</version> </parent> <groupId>acme</groupId> <artifactId>Product</artifactId> <packaging>pom</packaging> <modules> <module>A</module> <module>B</module> </modules> ``` root/A/pom.xml: ``` <project ...> <parent> <groupId>acme</groupId> <artifactId>ParentPom</artifactId> <relativePath>../parent-pom.xml</relativePath> <version>1.0.0-SNAPSHOT</version> </parent> <groupId>acme</groupId> <artifactId>A</artifactId> <packaging>jar</packaging> ``` root/B/pom.xml: ``` <project ...> <parent> <groupId>acme</groupId> <artifactId>ParentPom</artifactId> <relativePath>../parent-pom.xml</relativePath> <version>1.0.0-SNAPSHOT</version> </parent> <groupId>acme</groupId> <artifactId>B</artifactId> <packaging>jar</packaging> <dependencies> <dependency> <groupId>acme</groupId> <artifactId>A</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> </dependencies> ```