0

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
Community
  • 1
  • 1
user3177112
  • 395
  • 1
  • 2
  • 12
  • Can you post all of your POM? Maybe there's a version mismatch? – Tunaki Jun 17 '16 at 11:49
  • @Tunaki here, I've created a structure, representing this structure. Try to build sub-parent: http://dropmefiles.com/5l42j – user3177112 Jun 17 '16 at 12:11
  • @Tunaki added poms – user3177112 Jun 17 '16 at 12:27
  • 2
    You should start the build from `parent` and not from `sub-parent1`, see also http://stackoverflow.com/a/33131999/1743880 – Tunaki Jun 17 '16 at 12:28
  • 1
    Possible duplicate of [Maven multi module project cannot find sibling module](http://stackoverflow.com/questions/33131880/maven-multi-module-project-cannot-find-sibling-module) – Tunaki Jun 17 '16 at 12:48
  • Glad I could help. I flagged it as duplicate then. Feel free to accept it so that future visitors are redirected to the answer. – Tunaki Jun 17 '16 at 12:49

1 Answers1

0

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
user3177112
  • 395
  • 1
  • 2
  • 12