1

I have a very complex multi-module Maven project with nested projects. basically, the problem can be simplified to this configuration :

    Project A
|   pom.xml
|   pomBis.xml
|
|---- Project B
        pom.xml
        pomBis.xml
        ---- Project D
            pom.xml
        ---- Project E
            pom.xml
|---- Project C
        pom.xml

The pom of the Project A has Project B and C as modules. And in the pom of Project B, I only have Project D. Because Project E is a very large project that we don't need to compile everyday, it is excluded of the daily build.

I now want to execute a Maven command, for example the versions:update-parent. I want ALL my projects and sub-project to be updated. If I use the pom.xml, the Project E will not be updated because it is not declared as a sub-module of Project B.

I thought of creating a custom pomBis.xml that would be used. But if I create a pomBis.xml on each sub-project, and run the command, only the pomBis.xml of Project A is used. When Maven is going deeper, it falls back to normal pom.xml.

The only solution I see is to create a pomBis.xml in Project A that will list all sub-modules and really list all leaf projects.

Am I getting something wrong?

Maxoudela
  • 2,091
  • 3
  • 15
  • 23
  • Project C appear twice in your tree. Could you please correct that? – J Fabian Meier Apr 25 '17 at 13:54
  • Thanks, corrected. – Maxoudela Apr 25 '17 at 14:00
  • If you correctly handle the whole structure as a single multi module build you can control what will be built by using `mvn -pl projectToBuild ` furthermore you can define what should be built based on the given projectToBuild and which depends on that via `mvn -pl projectToBuild --also-make-dependent`. Apart from that you can use incremental build in Jenkins to build only what has changed... – khmarbaise Apr 25 '17 at 19:33

1 Answers1

1

Maven profile is the answer.

Project A POM:

<pom>
.
.
.
<modules>
    <module>B</module>
    <module>C</module>
<modules>
</pom>

Project B POM:

<pom>
.
.
.
<profiles>
    <profile>
        <id>includebeast</id>
        <modules>
            <module>E</module>
        <modules>       
    </profile>
</profiles>
<modules>
    <module>D</module>
<modules>
</pom>

Now, when you want your maven command affect all your projects, activate the profile "includebeast" as like below example:

Example to compile all : mvn clean compile -P includebeast

Shailesh Pratapwar
  • 4,054
  • 3
  • 35
  • 46
  • Thanks, I'll also link to this issue : https://stackoverflow.com/questions/10682186/in-maven-can-a-profile-override-the-modules-to-not-include-any Because the default modules are included with your profile. In case I want just my module in my profile, I can use the activations. – Maxoudela Apr 27 '17 at 15:51