Search code examples
mavenbuildmulti-modulemaven-module

Maven build skips submodules which are dependency in another module


I have nested multi module maven structure like this:

main_aggregator
|- submodule_A
|  |- sub_submodule_1
|  |- sub_submodule_2
|- submodule_B
|- submodule_C

pom.xml in main_aggregator has this in modules

<modules>
    <module>submodule_A</module>
    <module>submodule_B</module>
    <module>submodule_C</module>
</modules>

pom.xml in submodule_A has this in modules

<modules>
    <module>sub_submodule_1</module>
    <module>sub_submodule_2</module>
</modules>

parent of main_aggregator's sub modules is something like this:

<parent>
    <groupId>my.project</groupId>
    <artifactId>main-parent</artifactId>
    <version>0.0.1</version>
    <relativePath/>
</parent>

parent of submodule_A's sub modules is something like this:

<parent>
    <groupId>my.project</groupId>
    <artifactId>specific-parent</artifactId>
    <version>0.0.1</version>
    <relativePath/>
</parent>

The important thing is that submodule_B has dependencies on sub_submodule_1 and sub_submodule_2

When I run build from main_aggregator, it fails and says it could not resolve depenencies for submodule_B - sub_submodule_1 and sub_submodule_2.

In reactor summary I see, that submodule_A was built first and built is success, but it's sub modules - sub_submodule_1 and sub_submodule2 are skipped. So I understand, why it fails on missing dependencies, but what I don't understand is why maven didn't built those dependencies first. Also I don't understand why build of submodule_A is marked as successful when it's sub modules wasn't even built.

Maven version is 3.5.2.

Update: When I run build in one thread, there is no problem. Problem occurs only when doing parallel build.

Update2: Running in single thread was only partial success. See my answer...


Solution

  • So I found out what was the problem. The problem was some kind of "copy paste exception". In submodule_A which is an aggregator, I have copied pom from main_aggregator. Of course I changed main things like group id and artifact id, but I didn't change plugins.

    Plugin which caused that problems was javadoc. Particularly it's agregate goal. When I deleted it, I could build whole project (but not in parallel).

    Problem was, that evidently during parallel builds, aggregators projects are build "out of order" because it has no dependencies (submodule_A start build before it's submodules were build). Now javadoc aggregate comes to play.

    Javadoc aggregate forked every submodule build (maybe this is wrong terminology). But this was not ordered by dependencies, so it fails.

    There still is problem with parallel builds, because aggregate goal of javadoc in main_aggregator cause the same problem. But that is for another question.

    There is one more lesson I learned from that. If I would put content of whole pom.xml of each module in my question, somebody probably would see the problem.

    So when you are asking something, don't hide details even when you think they does not matter :)...