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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With