0

I have this dependencyManagement in my parent POM of my multi-module project:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>A</artifactId>
            <version>3.5</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>B</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>C</artifactId>
            <version>1.1</version>
        </dependency>
</dependencyManagement>

And this in every child module POM:

Module A:

<parent>
    <groupId>${project.groupId}</groupId>
    <artifactId>ParentId</artifactId>
    <version>1.0</version>
</parent>
<artifactId>A</artifactId>
<version>3.5</version>
<packaging>nbm</packaging>

Module B:

<parent>
    <groupId>${project.groupId}</groupId>
    <artifactId>ParentId</artifactId>
    <version>1.0</version>
</parent>
<artifactId>B</artifactId>
<version>1.0</version>
<packaging>nbm</packaging>

Module C:

<parent>
    <groupId>${project.groupId}</groupId>
    <artifactId>ParentId</artifactId>
    <version>1.0</version>
</parent>
<artifactId>C</artifactId>
<version>1.1</version>
<packaging>nbm</packaging>

Every time that we want to release, we have to check that the version in every child module is the same that the version in the dependencyManagement (developers are asked to change the version in both places every time they change something).

There is some way to check that the versions are the same automaticaly? If the versions are not the same, how could I change them automaticaly?

  • Shouldn't the artifactId for module B and C be `B` and `C` ?? – vikingsteve Oct 13 '15 at 08:31
  • You should consider defining the version in maven properties in the parent pom and refer the property in your child modules. That way they will all be in sync. – User2709 Oct 13 '15 at 08:40
  • If you have a multi module build every module / child should have the same version as the parent so you violating the idea of a multi module build which leads in problem you have. – khmarbaise Oct 14 '15 at 09:25
  • @vikingsteve You are right. I edited :) – Adrián Castillo Oct 14 '15 at 10:42
  • @SanjeevGour If I do what you say I will have a warning that says: "version contains an expression but should be a constant. It is highly recommended to fix these problems because they threaten the stability of your build. For this reason, future Maven versions might no longer support building such malformed projects." – Adrián Castillo Oct 14 '15 at 10:43
  • That sound like a strict check in Maven 3. You could also try keeping the version numbers in parent pom only and remove them from the child modules, they will inherit the version property from the parent pom. I am not sure if that will remove the warning. Could you give that a try? – User2709 Oct 14 '15 at 10:58

3 Answers3

0

Parent pom discovery-ui :

<parent>
    <groupId>${project.groupId}</groupId>
    <artifactId>discovery-ui</artifactId>
    <version>1.0</version>
</parent>

<properties>
        <A.version>3.5</A.version>
        <B.version>1.0</B.version>
        <C.version>1.1</C.version>
<properties>
        
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>A</artifactId>
            <version>${A.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>B</artifactId>
            <version>${B.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>C</artifactId>
            <version>${C.version}</version>
        </dependency>
</dependencyManagement>

Module A:

<parent>
    <groupId>${project.groupId}</groupId>
    <artifactId>discovery-ui</artifactId>
    <version>1.0</version>
</parent>
<artifactId>A</artifactId>
<version>${A.version}</version>
<packaging>nbm</packaging>
halfer
  • 19,824
  • 17
  • 99
  • 186
question_maven_com
  • 2,457
  • 16
  • 21
  • This way I have the following message: 'version' contains an expression but should be a constant. It is highly recommended to fix these problems because they threaten the stability of your build. For this reason, future Maven versions might no longer support building such malformed projects. – Adrián Castillo Oct 14 '15 at 10:45
0

Have you tried maven versions plugin? Looks like processParent parameter should do the trick. I have not tested it yet, though.

mvn versions:set -DgenerateBackupPoms=false -f A/pom.xml -DnewVersion=NEW_VERSION -DartifactId=A -DprocessParent=true
botchniaque
  • 4,698
  • 3
  • 35
  • 63
0

You already have declared dependencies and their versions in your parent POM under the <dependencyManagement> section. This way you need only to declare GroupID:ArtifactID in your child POM (without version, it will be inherited from the parent POM)

starling
  • 19
  • 3