0

I have 3 projects Parent,Child,SubChild.

Project Parent pom is as follows:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.3.RELEASE</version>
</parent>

<groupId>mu.parent</groupId>
<artifactId>parent-system</artifactId>
<version>1.0</version>
<packaging>pom</packaging>

....

Project Child pom is defined below and its Parent is defined follows:

<modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>mu.parent</groupId>
        <artifactId>parent-system</artifactId>
        <version>1.0</version>
    </parent>
    
    <groupId>mu.dummy.child</groupId>
    <artifactId>child-backend</artifactId>
    <name>child-backend</name>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

  <modules>
        <module>subChild-app</module>
  
    </modules>


...

Now subChild pom is as follows and the child is defined as parent for subChild :

 <parent>
            <groupId>mu.dummy.child</groupId>
           <artifactId>child-backend</artifactId>
          <version>0.0.1-SNAPSHOT</version>
    </parent>
 <groupId>mu.dummy.subchild</groupId>
    <artifactId>subchild-backend</artifactId>
    <name>subchild-backend</name>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

  <dependencies>
        <dependency>
            <groupId>org.project.test</groupId>
            <artifactId>project</artifactId>
       <version></version> --version of parent-system???
        </dependency>

    </dependencies>

Is it possible to get version of parent-system(1.0) in subchild-backend please without hardcoding it?

GDethier
  • 127
  • 10
user1999453
  • 1,297
  • 4
  • 29
  • 65

2 Answers2

1

You can use CI-friendly versions and write ${revision} for the versions, setting this property in the main pom (from which you build everything).

You need to use the flatten Maven plugin, though, to get proper POMs in the repository.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
0

I asked a similar question a while back and determined that tthe groovy-maven-plugin works for this. See this answer.

user944849
  • 14,524
  • 2
  • 61
  • 83
  • Hi i tried it but how do you access project.properties.setProperty('root.pom.version', pom.version); in your child pom? this is not working ${root.pom.version} – user1999453 Sep 10 '20 at 19:39
  • Glad you tried it. Looking again, this may not work where you want to use it. Maven resolves dependencies pretty early in the process, before executing plugins. I am curious as to why you need to specify a grandparent POM as a dependency though? – user944849 Sep 10 '20 at 20:39
  • basically the org.project.test is a common-project and its parent is parent-system.so its version should be align with the version of its parent – user1999453 Sep 11 '20 at 02:55
  • You might have better luck with something like the `maven-enforcer-plugin` then. It has a [list of rules](https://maven.apache.org/enforcer/enforcer-rules/index.html) you may apply, including some that manage versions. – user944849 Sep 11 '20 at 12:12