Purportedly you can exclude modules on the command line for example by running command like
mvn clean install -pl \!modulename
This does not seem to work (anymore).
Btw, include the module also doesn't work
mvn clean install -pl modulename
Maven reactor will not find the module and fail.
[ERROR] Could not find the selected project in the reactor: modulename -> [Help 1]
The module modulename
does exist however. Reactor will produce its name in the list of build modules when doing an ordinary build.
[INFO] modulename
Is there a way to exclude modules on the command line? I don't want to change the pom file if it all possible.
Answer 1: Maven version 3.2. 1 added this feature, you can use the -pl switch (shortcut for --projects list) with ! or - (source) to exclude certain submodules. Be careful in bash the character ! is a special character, so you either have to single quote it (like I did) or escape it with the backslash character.
Multiple transitive dependencies can be excluded by using the <exclusion> tag for each of the dependency you want to exclude and placing all these exclusion tags inside the <exclusions> tag in pom. xml. You will need to mention the group id and artifact id of the dependency you wish to exclude in the exclusion tag.
To skip running the tests for a particular project, set the skipITs property to true. You can also skip the tests via the command line by executing the following command: mvn install -DskipTests.
Lets say in your parent pom.xml, your module structure is this:
Then if I want to exclude modules "core" and "app1", the command would be:
mvn -pl '!core,!app1' clean install
So the end result with the -pl flag is:
Note:
Put the module names from the parent pom.xml (like above), not the <name>
in the sub-modules.
Put the -pl flag before "clean install".
Also, there should be no spaces between each of the commas separating the module names.
This is what the build looks like without the -pl flag set:
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