5

the question was asked many times but I didnt find a solution, how to disable also the child modules of a module!?!

For example: I want to disable projects BB and CC AND also their child modules

A
|-AA
|  |--AAA
|-BB
|  |-BBB
|-CC
   |-CCC

But when I run this

mvn -pl \!AA,\!BB clean install

I see that also BBB and CCC are executed. This here is only a sample. We have a multi module project with about a hundred projects ... soo I dont want to list all project, only the parents. Is this possible?

Thank you

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
pan40
  • 317
  • 1
  • 5
  • 15

1 Answers1

3

You could use Maven profiles for your purpose.

In the parents projects you could define a profile which overrides the modules section providing all the required modules. Such a profile would be active by default, so no changes on the expected behavior.

However, the modules section of the normal POM (out of profiles) will be empty. Note that we cannot do the opposite (which would make more sense): I just tried it and it didn't work.

So, such a sample POM would look like:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sample</groupId>
<artifactId>test3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
</modules>

<profiles>
    <profile>
        <id>aggregator</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <modules>
            <module>..\test</module>
            <module>..\test2</module>
        </modules>
    </profile>
</profiles>

Executing:

mvn clean install

Maven will also activate the profile and perform the aggregator build as expected. So, no regressions.

However, when executing:

mvn clean install -P!aggregator

Maven will deactivate the profile above and as such perform a reactor build with no modules, executing only the parent as you wished.
Pity the reverse approach (profile with empty modules) didn't work on my test, but the approach should hopefully give you enough hints to reach your goal.


Update
You are actually using this new feature available since Maven 3.2.1. From the comments on the ticket, somebody had the same question:

how about excluding nested modules? I tried the new feature and it seems as though:
1. when a top module is excluded, its nested modules are not.
2. it is not possible to exclude nested modules directly.

Answer was:

Nested modules are not excluded by parent module. The exclusion method mimics the inclusion method and its matcher does not support wildcards etc. So to cascade exclusion would necessitate an extra flag like -amd. The dependency graph is filtered in the following order when using -pl:
1. included projects + possibly upstream and downstream
2. excluded projects
3. skipping for resume projects
So it should be possible to directly exclude nested modules as they should be present in the intial dependency graph before filtering starts.

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
  • Hi thanks for your answer, my first purpose was not to use profiles, because of our internal team structure ... but I will think about it. We use maven 3.2.3 but I can not understand which new feature is meant by this post. -el is not a existing maven option – pan40 Jan 20 '16 at 10:42
  • I'll update my answer, you were actually using it, the -el suggestion was discarded in favor of -pl !sub-module. However, in the comments somebody had exactly your same question – A_Di-Matteo Jan 20 '16 at 10:52