Is it possible to have a parent version as a property to provide to children?

This is about Maven POM's

If I wanted the version of my parent to also be the version of my dependencies, I must set the value of the property to $ {project.parent.version}.

The problem arises when the child of my main POM (which has the property $ {project.parent.version} inside it, because it is the parent, is some kind of project that I do not administer), recount the property and think that the value of the created Properties is now a version of my main POM.

--SuperParent (not in my Administration) | Version = 1.2.3 ----MainPom | Version = 1.0.0 | Property <test>${project.parent.version}</test> -> 1.2.3 ------Child Pom | Version 1.0.0 | Property ${test} is now 1.0.0 

 <project> <!-- Super Pom --> <groupId>groupId</groupId> <artifactId>artifactId</artifactId> <version>1.2.3</version> </project> <project> <!-- MainPom --> <groupId>othergroupId</groupId> <artifactId>otherartifactId</artifactId> <version>1.0.0</version> <parent> <groupId>groupId</groupId> <artifactId>artifactId</artifactId> <version>1.2.3</version> </parent> <properties> <dependency.version>${project.parent.version}</dependency.version> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>dependencyGroupId<groupId> <artifactId>dependency</artifactId> <version>${dependency.version}</version> </dependency> </dependencies> </dependencyManagement> </project> <project> <!-- ChildPom --> <groupId>childGroupId</groupId> <artifactId>childArtifactId</artifactId> <version>1.0.0</version> <parent> <groupId>othergroupId</groupId> <artifactId>otherartifactId</artifactId> <version>1.0.0</version> </parent> <dependencies> <dependency> <groupId>dependencyGroupId<groupId> <artifactId>dependency</artifactId> </dependency> </dependencies> </project> 

At the end, the $ {dependency.version} property is used in Child Pom 1.0.0 instead of 1.2.3. Is this a desirable Maven behavior? And what could I do to make it work?

Things that cannot be changed:

  • Superpom
  • The main version of Pom
+5
source share
1 answer

Maven first inherits the process to create an effective pom, and then extends the process variables.

In other words, the contents of the parent and child pom are treated as a single merged file for each child pom. Therefore, when your child pom is processed, $ {project.parent.version} is 1.0.0, not 1.2.3.

I could not find a way to refer to the "grandparent" pom, so it seems that the only solution is to put the version as a static number in both parent.version and properties.dependency.version.

+4
source

Source: https://habr.com/ru/post/1259093/


All Articles