Reputation: 4353
I've read this and that. They have basically the same content except some wording difference. There is a critical word in the latter that that I want to point out:
The configuration elements are recursively merged based on the element name, ...
where in the former it just says:
The default behavior is to merge the content of the configuration element according to element name. If the child POM has a particular element, that value becomes the effective value. if the child POM does not have an element, but the parent does, the parent value becomes the effective value.
My question is when the configuration element is a nested element. Let's say that in my parent pom.xml, I have:
<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>
...
Then in my child pom, I have:
<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>
...
As you can see, I'm trying to include
a dependency that the parent bom exclude
ed. Since the element I'm trying to merge here (<excludes>
and <includes>
) are inside </rules>/</bannedDependencies>
, I don't know if I will get:
<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>
...
or just what the child pom specifies (in other words, the nested element in the parent pom gets replaced with the element in the child pom).
Upvotes: 2
Views: 1769
Reputation: 4711
You will get both includes
and excludes
. You can verify this by running mvn help:effective-pom
. The enforcer plugin treats includes as exceptions to the excludes, so excluding and then including the same artifact should have the effect that it's not banned (although I haven't tested this).
When I'm in doubt about configuration inheritance, I imagine maven recursively merging the configuration elements from the innermost element and outwards, so in this case, the bannedDependencies
element gets both the includes
element from the child and the excludes
element from the parent. If you don't want the child to inherit anything from the bannedDependencies
element, you can do the following in the child pom:
<bannedDependencies combine.self="override">
...
</bannedDependencies>
Upvotes: 7