Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude Maven modules on command line

Tags:

maven

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.

like image 337
onknows Avatar asked Dec 17 '15 20:12

onknows


People also ask

How do I skip a particular module in Maven?

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.

How do I exclude a specific version of Maven?

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.

How do I skip a project in Maven build?

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.


1 Answers

Lets say in your parent pom.xml, your module structure is this:

enter image description here

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:

enter image description here

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: enter image description here

like image 102
Gene Avatar answered Oct 20 '22 17:10

Gene