why does maven search for parent_project:pom:${revision} when building this child_project?

27 Views Asked by At

background

directory layout

|
|`parent_project/pom.xml
|
|`child_project/pom.xml

parent pom

<?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>org.example</groupId>
    <artifactId>parent_project</artifactId>
    <version>${revision}</version>
    <packaging>pom</packaging>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>
</project>

child pom

<?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>

    <parent>
        <artifactId>parent_project</artifactId>
        <groupId>org.example</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>child_project</artifactId>
    <version>${revision}</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>
</project>

steps to produce issue

  1. build parent
mvn clean install -Drevision=1.0-SNAPSHOT -U -f pom.xml
  1. build child
mvn clean install -Drevision=1.0-SNAPSHOT -U -f pom.xml
  1. get error
Could not find artifact org.example:parent_project:pom:${revision} in remote-repo (url)

question

I specified the parent version as 1.0-SNAPSHOT in the child's parent block, so why is maven trying to find org.example:parent_project:pom:${revision}?

the ${revision} folder is added to the local repository parent_project directory when maven starts looking for ${revision} while building the child_project

the ${revision} directory is added to .m2/repository/.../parent_project/ when maven starts looking for parent_project:pom:${revision} while building child_project

1

There are 1 best solutions below

0
Gunnar On

answer reworked, checkout the links at the end for documentations multi module project and ci friendly links with revision parameter.

Example (building parent builds also children, building a child just builds that child):

directory layout

  • ...\parent\pom.xml
  • ...\parent\child1\pom.xml
  • ...\parent\child2\pom.xml

parent pom

<?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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>so</groupId>
    <artifactId>parent-project</artifactId>
    <version>${revision}</version>
    <packaging>pom</packaging>

    <properties>
        <revision>1.0.0-DEFAULT</revision>
    </properties>

    <modules>
        <module>child1-project</module>
        <module>child2-project</module>
    </modules>

</project>

child poms (also packaging pom to create a minimal example)

<?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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>parent-project</groupId>
    <artifactId>child1-project</artifactId>
    <packaging>pom</packaging>

    <parent>
        <groupId>so</groupId>
        <artifactId>parent-project</artifactId>
        <version>${revision}</version>
    </parent>

</project>

and

<?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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>parent-project</groupId>
    <artifactId>child2-project</artifactId>
    <packaging>pom</packaging>

    <parent>
        <groupId>so</groupId>
        <artifactId>parent-project</artifactId>
        <version>${revision}</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>parent-project</groupId>
            <artifactId>child1-project</artifactId>
            <version>${revision}</version>
            <type>pom</type>
        </dependency>
    </dependencies>

</project>

links