title: maven plugin configuration inheritance (merging strategy for nested elements)
body: <p>I've read <a href="https://maven.apache.org/pom.html#Plugins" rel="nofollow noreferrer">this</a> and <a href="http://blog.sonatype.com/2011/01/maven-how-to-merging-plugin-configuration-in-complex-projects/" rel="nofollow noreferrer">that</a>. 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:</p>
  
  <blockquote>
    <p>The configuration elements are <strong>recursively</strong> merged based on the element name, ...</p>
  </blockquote>
  
  <p>where in the former it just says:</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>My question is when the configuration element is a nested element. Let's say that in my parent pom.xml, I have:</p>
  
  <pre><code>&lt;build&gt;
  &lt;plugins&gt;
  &lt;plugin&gt;
  &lt;executions&gt;
    &lt;execution&gt;
      &lt;id&gt;enforce-maven&lt;/id&gt;
      &lt;goals&gt;
        &lt;goal&gt;enforce&lt;/goal&gt;
      &lt;/goals&gt;
      &lt;configuration&gt;
          &lt;rules&gt;
              &lt;bannedDependencies&gt;
                  &lt;excludes&gt;
                      &lt;exclude&gt;com.my.group:my.id&lt;/exclude&gt;
                  &lt;/excludes&gt;
              &lt;/bannedDependencies&gt;
          &lt;/rules&gt;
      &lt;/configuration&gt;
      ...
  </code></pre>
  
  <p>Then in my child pom, I have:</p>
  
  <pre><code>&lt;build&gt;
  &lt;plugins&gt;
  &lt;plugin&gt;
  &lt;executions&gt;
    &lt;execution&gt;
      &lt;id&gt;enforce-maven&lt;/id&gt;
      &lt;goals&gt;
        &lt;goal&gt;enforce&lt;/goal&gt;
      &lt;/goals&gt;
      &lt;configuration&gt;
          &lt;rules&gt;
              &lt;bannedDependencies&gt;
                  &lt;includes&gt;
                      &lt;include&gt;com.my.group:my.id&lt;/include&gt;
                  &lt;/includes&gt;
              &lt;/bannedDependencies&gt;
          &lt;/rules&gt;
      &lt;/configuration&gt;
      ...
  </code></pre>
  
  <p>As you can see, I'm trying to <code>include</code> a dependency that the parent bom <code>exclude</code>ed. Since the element I'm trying to merge here (<code>&lt;excludes&gt;</code> and <code>&lt;includes&gt;</code>) are inside <code>&lt;/rules&gt;/&lt;/bannedDependencies&gt;</code>, I don't know if I will get:</p>
  
  <pre><code>&lt;build&gt;
  &lt;plugins&gt;
  &lt;plugin&gt;
  &lt;executions&gt;
    &lt;execution&gt;
      &lt;id&gt;enforce-maven&lt;/id&gt;
      &lt;goals&gt;
        &lt;goal&gt;enforce&lt;/goal&gt;
      &lt;/goals&gt;
      &lt;configuration&gt;
          &lt;rules&gt;
              &lt;bannedDependencies&gt;
                  &lt;excludes&gt;
                      &lt;exclude&gt;com.my.group:my.id&lt;/exclude&gt;
                  &lt;/excludes&gt;
                  &lt;includes&gt;
                      &lt;include&gt;com.my.group:my.id&lt;/include&gt;
                  &lt;/includes&gt;
              &lt;/bannedDependencies&gt;
          &lt;/rules&gt;
      &lt;/configuration&gt;
      ...
  </code></pre>
  
  <p>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). </p>