Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excluding a child module from being executed in Maven via a command line option

Tags:

maven

I have a maven project with 5 children, however when I run it, I want the last one not to be executed. I could easily commend it out from the pom file for that, however I would like to know, is there a command line option to exclude a child module from being executed?

like image 642
Elchin Avatar asked Nov 30 '25 09:11

Elchin


2 Answers

I have this configuration in the current project I am working on to exclude some modules.

In your pom that declares the modules, just put the list of the modules you want to run every time:

<modules>
    <module>this-is</module>
    <module>always-needed</module>
</modules>

and then, add a profile section in the same pom and move the modules you don't want to run every time:

<profiles>
    <profile>
        <id>do-additional-module</id>
        <modules>
            <module>this-is-rarely-needed</module>
        </modules>
    </profile>
</profiles>

Now when you run mvn package, only the modules this-is and always-needed are executed and when you specify the profile mvn -P do-additional-module package the reactor will run the previous modules and this-is-rarely-needed.

M.

like image 87
poussma Avatar answered Dec 02 '25 05:12

poussma


You can achieve this with a profile. A maven profile in the parent pom.xml can include additional child modules.

Here's an example. Whem activated, this "include" profile will include a second child module.

<modules>
    <module>child-module-one</module>
</modules>
<profiles>
    <profile>
        <id>include</id>
        <modules>
            <module>child-module-two</module>
        </modules>
    </profile>
</profile>

If you trigger a maven build phase at the parent level (compile in this example), and activate this profile - e.g.

mvn compile -P include

you will include your second child module. If you were to avoid activating that profile, e.g. by just running:

mvn compile

then your second child module is not included.

like image 26
serg10 Avatar answered Dec 02 '25 04:12

serg10



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!