我已阅读this和that。除了一些措辞差异外,它们的内容基本相同。后者有一个关键词,我想指出:
配置元素递归根据元素名称合并<...
前者只说:
默认行为是根据元素名称合并配置元素的内容。如果子POM具有特定元素,则该值将成为有效值。如果子POM没有元素,但是父元素,则父值变为有效值。
我的问题是配置元素是嵌套元素的时候。让我们说在我的父pom.xml中,我有:
<build>
<plugins>
<plugin>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedDependencies>
<excludes>
<exclude>com.my.group:my.id</exclude>
</excludes>
</bannedDependencies>
</rules>
</configuration>
...
然后在我的孩子pom中,我有:
<build>
<plugins>
<plugin>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedDependencies>
<includes>
<include>com.my.group:my.id</include>
</includes>
</bannedDependencies>
</rules>
</configuration>
...
正如您所看到的,我尝试include
父母exclude
编辑的依赖关系。由于我尝试在此处合并的元素(<excludes>
和<includes>
)位于</rules>/</bannedDependencies>
内,我不知道是否会获得:
<build>
<plugins>
<plugin>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<bannedDependencies>
<excludes>
<exclude>com.my.group:my.id</exclude>
</excludes>
<includes>
<include>com.my.group:my.id</include>
</includes>
</bannedDependencies>
</rules>
</configuration>
...
或者只是孩子pom指定的内容(换句话说,父pom中的嵌套元素被子pom中的元素替换)。
答案 0 :(得分:1)
您将同时获得includes
和excludes
。您可以通过运行mvn help:effective-pom
来验证这一点。执行器插件处理包括作为排除的例外,因此排除然后包括相同的工件应该具有不被禁止的效果(尽管我没有测试过)。
当我对配置继承有疑问时,我想maven以递归方式合并 innermost 元素中的配置元素并向外,因此在这种情况下,bannedDependencies
元素同时获取来自子项的includes
元素和来自父项的excludes
元素。如果您不希望孩子继承bannedDependencies
元素中的任何内容,您可以在子pom中执行以下操作:
<bannedDependencies combine.self="override">
...
</bannedDependencies>