4

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>
Community
  • 1
  • 1
franck102
  • 221
  • 4
  • 14

1 Answers1

5

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
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • I have factored out "other default setup", this doesn't require a separate project, I simply have a pom-parent.xml. The release plug-in won't work when the version is defined in that parent POM, which is how I avoid replicating in each and every module. – franck102 Jul 13 '12 at 13:59
  • You are talking about a pom-parent.xml which is the one i mentioned root/pom.xml no other. The other company pom must be a separate project to use it as a parent in the root/pom.xml. The version is defined only once in the parent pom (root/pom.xml) and used on the modules in parent reference. – khmarbaise Jul 13 '12 at 14:16
  • I think I understand what you propose, which amounts to "moving product-wide build steps to a separate module" as I mentioned initially, doesn't it? Because those steps can't live in root/pom.xml if that pom is the parent of each module pom... maybe be that is the right thing to do, I will try it out - thanks! – franck102 Aug 03 '12 at 17:07
  • Totally agree. Its exactly that way. – khmarbaise Aug 03 '12 at 17:17
  • This maven plugin can solve this kind of problem too: http://mojo.codehaus.org/flatten-maven-plugin/examples/example-multiple-versions.html – Stephan Jun 12 '14 at 14:50