How to exclude a module and its child modules from a Maven reactor build?

pan*_*n40 5 pom.xml maven-3 maven maven-module

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
Run Code Online (Sandbox Code Playgroud)

But when I run this

mvn -pl \!AA,\!BB clean install
Run Code Online (Sandbox Code Playgroud)

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_D*_*teo 3

您可以使用Maven 配置文件来达到您的目的。

在父项目中,您可以定义一个配置文件来覆盖modules提供所有必需模块的部分。这样的配置文件默认处于活动状态,因此预期行为不会发生变化。

然而,modules正常 POM 的部分(在配置文件之外)将为空。请注意,我们不能做相反的事情(这会更有意义):我刚刚尝试过,但它不起作用。

因此,这样的 POM 示例将如下所示:

<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>
Run Code Online (Sandbox Code Playgroud)

执行:

mvn clean install
Run Code Online (Sandbox Code Playgroud)

Maven 还将激活配置文件并按预期执行聚合器构建。所以,没有回归。

但是,执行时:

mvn clean install -P!aggregator
Run Code Online (Sandbox Code Playgroud)

Maven 将停用上面的配置文件,并因此执行不带模块的反应器构建,仅根据您的意愿执行父级。
遗憾的是,相反的方法(具有空模块的配置文件)在我的测试中不起作用,但该方法有望为您提供足够的提示来实现您的目标。


更新
您实际上正在使用自 Maven 3.2.1以来提供的这个新功能。从票上的评论来看,有人提出了同样的问题:

排除嵌套模块怎么样?我尝试了新功能,看起来好像:
1. 当顶部模块被排除时,它的嵌套模块不会被排除。
2. 无法直接排除嵌套模块。

答案是:

嵌套模块不会被父模块排除。排除方法模仿包含方法,其匹配器不支持通配符等。因此,级联排除需要一个额外的标志,如 -amd。使用 -pl 时,依赖关系图按以下顺序过滤:
1. 包含的项目 + 可能是上游和下游
2. 排除的项目
3. 跳过恢复项目
因此应该可以直接排除嵌套模块,因为它们应该存在于过滤开始之前的初始依赖图。