Search code examples
mavenmaven-reactor

Maven hierarchical dependency search


So I have a problem, that is - Maven seems to ignore dependencies, even though they should be visible in hierarchy.

I have following project hierarchy:
parent
--projA
--sub-parent1
----projB
----projC

All levels are linked via <parent> tag. sub-parent1 has projB and projC declared as modules and no dependencies declared. But projB has a dependency on projA. And building entire sub-parent1 module will not build projA, which is strange, because projB is aware of sub-parent1 and sub-parent1 is aware of parent and it is aware of dependency (projA). But maven do not build it whenever I build entire sub-parent1 or, for example, -pl projB -am clean install.
Any help appreciated.

Edit: I've created a structure, representing this structure. Try to build sub-parent: dropmefiles.com/5l42j

Edit: parent pom:

<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>test</groupId>
    <artifactId>parent</artifactId>
    <packaging>pom</packaging>
    <version>1.0</version>


    <modules>
        <module>projA</module>
        <module>sub-parent1</module>
    </modules>

</project>

projA:

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

    <parent>
        <groupId>test</groupId>
        <artifactId>parent</artifactId>
        <version>1.0</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>projA</artifactId>
    <version>1.0</version>

</project>

sub-parent1:

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

    <parent>
        <groupId>test</groupId>
        <artifactId>parent</artifactId>
        <version>1.0</version>
    </parent>

    <artifactId>sub-parent1</artifactId>
    <packaging>pom</packaging>
    <version>1.0</version>

    <modules>
        <module>projB</module>
    </modules>

</project>

projB:

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

    <parent>
        <groupId>test</groupId>
        <artifactId>sub-parent1</artifactId>
        <version>1.0</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>projB</artifactId>
    <version>1.0</version>

    <dependencies>
        <dependency>
            <groupId>test</groupId>
            <artifactId>projA</artifactId>
            <version>1.0</version>
        </dependency>
    </dependencies>

</project>

Edit: Although I had the same solution as in Maven multi module project cannot find sibling module - this problem is different as it deals with not only with multimodule, but with multilevel (several levels of modules) project and person there did not told maven explicitly to build dependencies aswell.

Solution: So it seems the only solution is - build such multilevel structure from the upper-most level pom, in my case it will be parent (so parent is current dir) and address module you need to build by relative path from the parent. That results in:

mvn -pl sub-parent1/projB -am clean install

The order will be:

[INFO] Reactor Build Order:
[INFO]
[INFO] parent
[INFO] projA
[INFO] sub-parent1
[INFO] projB

Solution

  • So it seems the only solution is - build such multilevel structure from the upper-most level pom, in my case it will be parent (so parent is current dir) and address module you need to build by relative path from the parent. That results in:

    mvn -pl sub-parent1/projB -am clean install
    

    The order will be:

    [INFO] Reactor Build Order:
    [INFO]
    [INFO] parent
    [INFO] projA
    [INFO] sub-parent1
    [INFO] projB