72

Is there a way to exclude some modules from a big reactor build, similar to -pl ?

Here are a number of ways to do it persistently:

How to exclude a module from a Maven reactor build?

I want to do it from shell, or at least without modifying the poms, which I am not allowed to change.

Naman
  • 27,789
  • 26
  • 218
  • 353
Bastl
  • 2,926
  • 5
  • 27
  • 48

7 Answers7

116

Maven 3.2.1 has added this feature, you can use to specify the exact projects you want (or to exclude the projects you don't want) -pl or --projects Here's how to exclude two:

-pl "!<modulename>,!<modulename2>"

for exclude certain modules. This can be comma separated list of values that you want to include/exclude.

Update For windows user following

> mvn clean [package|install] --projects \!groupId:artifactId
Ratul Sharker
  • 7,484
  • 4
  • 35
  • 44
Yogesh_D
  • 17,656
  • 10
  • 41
  • 55
66

Another comment on the accepted answer, don't forget to escape the exclamation sign when running the command in bash:

> mvn clean install -pl \!module,\!module/submodule,\!groupId:artifactId
Radu
  • 2,027
  • 1
  • 15
  • 10
19

As Yogesh_D wrote it can be done with the -pl argument with maven 3.2.1+

Here's an example:

> mvn clean install -amd -pl !module,!module/submodule

You need to list every sub-module (and sub-sub-module etc) manually, it does not exclude them recursively. Use the slash for package separation. It's the folder path, not the group or artifact id.

rogerdpack
  • 62,887
  • 36
  • 269
  • 388
Gonfi den Tschal
  • 1,754
  • 1
  • 20
  • 29
6

I don't believe this is currently possible from the command line. There is an open feature request in maven3 for this very thing (https://issues.apache.org/jira/browse/MNG-5230).

Looks like your only option at this point is to modify the pom and create a new build profile that includes only the modules you want to build.

Slawomir Jaranowski
  • 7,381
  • 3
  • 25
  • 33
gregwhitaker
  • 13,124
  • 7
  • 69
  • 78
4

Instead of using exclamation ! sign you can use minus - sign.

mvn clean -pl -module1

You can also exclude multiple modules.

mvn clean -pl -module1,-module2

or

mvn clean -pl -module1 -pl -module2

Tested with:

  • Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T20:33:14+02:00)
  • Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)

Excluded modules must be in reactor of current project, so we can't exclude no existing module.

mvn clean -pl -no-existing-module 

currently will fail - https://issues.apache.org/jira/browse/MNG-7033

Slawomir Jaranowski
  • 7,381
  • 3
  • 25
  • 33
1

in 2019 it's

mvn install -pl !:module1

(Windows 10 cmd)

davidluckystar
  • 928
  • 5
  • 15
-2

comma separated module name enclosed with double quotes. eg::

mvn install -pl "!Module1, !Module2" 
Nirbhay Rana
  • 4,229
  • 2
  • 18
  • 4