mavenjarmaven-3pom.xmlparent-pom

maven using parent dependencyManagement with ${project.version} causes dependency in wrong version


I have the following structure with the following dependency: child1->child2.

and a parent for both which consolidates all versions in dependency management, using ${project.version}.

Folder structures:

+ parent
  + child1
  + child2

See poms below + complete example here.

Everything works find when child2's version is set to 1.0-SNAPSHOT.

When trying to change just child2's version to 2.0-SNAPSHOT, I get the following error:

Failure to find ...:child1:jar:2.0-SNAPSHOT

Why is maven trying to find version child1 2.0 and not 1.0?

Parent:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>info.fastpace.issue.unknowversion</groupId>
    <artifactId>parent</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>

    <modules>
        <module>child1</module>
        <module>child2</module>
    </modules>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>info.fastpace.issue.unknowversion</groupId>
                <artifactId>child1</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>info.fastpace.issue.unknowversion</groupId>
                <artifactId>child2</artifactId>
                <version>${project.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>

Child1:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <artifactId>child1</artifactId>

    <parent>
        <groupId>info.fastpace.issue.unknowversion</groupId>
        <artifactId>parent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
</project>

Child2:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <artifactId>child2</artifactId>
    <version>2.0-SNAPSHOT</version>

    <parent>
        <groupId>info.fastpace.issue.unknowversion</groupId>
        <artifactId>parent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>info.fastpace.issue.unknowversion</groupId>
            <artifactId>child1</artifactId>
        </dependency>
    </dependencies>
</project>

Solution

  • It seems that replacing ${project.version} in the parent pom with hard coded 1.0-SNAPSHOT solved this.

    Don't know exactly why changing to hard coded values worked, but at least works now.