52

How is placeholder ${project.version} resolved for managed properties from parent pom? I've expected that it is resolved globally, so when the parent pom has version 2, ${project.version} would also be resolved to version 2.

In parent pom I have:

<groupId>my.group</groupId>
<artifactId>parent</artifactId>
<version>2</version>
<packaging>pom</packaging>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>my.group</groupId>
            <artifactId>dep</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>
</dependencyManagement>     

In child I use

<parent>
    <groupId>my.group</groupId>
    <artifactId>parent</artifactId>
    <version>2</version>
</parent>
<version>1</version>
<artifactId>child</artifactId>

But the artifact my.group.dep.1.jar is used, instead of my.group.dep.2.jar. So the placeholder is resolved to the version of the project using the managed dependency, and not those of the project defining the dependency.

Is that expected behaviour? I'm using maven 3.0.4.

Aritz
  • 30,971
  • 16
  • 136
  • 217
Danubian Sailor
  • 1
  • 38
  • 145
  • 223

1 Answers1

44

You have to skip <version> tag in child, but keep the <parent><version> ... </parent> tag.

http://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Project_Inheritance

One factor to note is that these variables are processed after inheritance as outlined above. This means that if a parent project uses a variable, then its definition in the child, not the parent, will be the one eventually used.

Abdull
  • 26,371
  • 26
  • 130
  • 172
terafor
  • 1,620
  • 21
  • 28
  • 1
    What if I don't want child to have the same version as parent? Typically, if they don't release at the same pace – Juh_ Jul 02 '21 at 13:47
  • @Juh_ then look into the parent pom, to check the name of the desired version property which you will override in your own pom. https://www.baeldung.com/spring-boot-starter-parent – Vergil333 Nov 08 '21 at 15:44