This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch maven-4.0.x
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/maven-4.0.x by this push:
     new f570f97701 [Backport maven-4.0.x] #13952: Respect plugin-level 
inherited=false when the plugin has executions (#14003)
f570f97701 is described below

commit f570f9770149f7d48eba51b4ef3f59c69b4bd555
Author: Guillaume Nodet <[email protected]>
AuthorDate: Sun Nov 15 22:17:55 2026 +0100

    [Backport maven-4.0.x] #13952: Respect plugin-level inherited=false when 
the plugin has executions (#14003)
    
    Port of #13952 and its forward-port (846c3eaebd) to maven-4.0.x.
    
    DefaultInheritanceAssembler.mergePluginContainer_Plugins() decided whether a
    parent build plugin participates in inheritance with:
    
      element.isInherited() || !element.getExecutions().isEmpty()
    
    so any parent plugin declaring at least one execution was folded into the 
child's
    effective plugin set regardless of an explicit inherited=false — exactly 
the kind
    of plugin declaration for which that flag matters most in practice.
    
    The fix: only commit the merged plugin to the inherited set once we know 
whether
    any of its executions actually survived the per-execution inherited 
filtering:
    - If none did, the plugin itself must not be inherited either (MNG-6373).
    - If at least one did, the whole plugin must still flow through (MNG-2103's
      documented execution-level override).
    
    Applied to both copies of DefaultInheritanceAssembler on maven-4.0.x:
    - compat/maven-model-builder (the Maven 3 compat layer)
    - impl/maven-impl (the Maven 4 impl layer, shares test resources via 
relative path)
    
    Fixes #7476.
---
 .../inheritance/DefaultInheritanceAssembler.java   | 12 +++--
 .../DefaultInheritanceAssemblerTest.java           | 20 +++++++
 .../inheritance/plugin-not-inherited-child.xml     | 28 ++++++++++
 ...ugin-not-inherited-execution-override-child.xml | 28 ++++++++++
 ...n-not-inherited-execution-override-expected.xml | 52 ++++++++++++++++++
 ...gin-not-inherited-execution-override-parent.xml | 58 ++++++++++++++++++++
 .../inheritance/plugin-not-inherited-expected.xml  | 49 +++++++++++++++++
 .../inheritance/plugin-not-inherited-parent.xml    | 63 ++++++++++++++++++++++
 .../impl/model/DefaultInheritanceAssembler.java    | 12 +++--
 .../model/DefaultInheritanceAssemblerTest.java     | 20 +++++++
 10 files changed, 336 insertions(+), 6 deletions(-)

diff --git 
a/compat/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.java
 
b/compat/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.java
index 1057d87695..82325dddc4 100644
--- 
a/compat/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.java
+++ 
b/compat/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.java
@@ -229,9 +229,15 @@ protected void mergePluginContainer_Plugins(
                         plugin.setGroupId(null);
                         mergePlugin(plugin, element, sourceDominant, context);
 
-                        Object key = getPluginKey(element);
-
-                        master.put(key, plugin);
+                        // a plugin marked inherited=false only reaches the 
child through an execution
+                        // whose own inherited flag overrides the plugin-level 
setting (MNG-2103); if no
+                        // execution survives that per-execution filtering, 
the plugin itself must not be
+                        // inherited either (MNG-6373), so only commit it once 
we know which case applies
+                        if (element.isInherited() || 
!plugin.getExecutions().isEmpty()) {
+                            Object key = getPluginKey(element);
+
+                            master.put(key, plugin);
+                        }
                     }
                 }
 
diff --git 
a/compat/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java
 
b/compat/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java
index 72d742a136..3096be80cd 100644
--- 
a/compat/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java
+++ 
b/compat/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java
@@ -64,6 +64,26 @@ void testPluginConfiguration() throws Exception {
         testInheritance("plugin-configuration");
     }
 
+    /**
+     * MNG-6373: a build plugin marked {@code inherited=false} must not reach 
child POMs,
+     * even when it declares an execution.
+     * @throws Exception
+     */
+    @Test
+    void testPluginNotInherited() throws Exception {
+        testInheritance("plugin-not-inherited");
+    }
+
+    /**
+     * MNG-2103: an execution's own {@code inherited=true} overrides a 
plugin-level
+     * {@code inherited=false}, so the whole plugin must still reach the child.
+     * @throws Exception
+     */
+    @Test
+    void testPluginNotInheritedWithInheritedExecutionOverride() throws 
Exception {
+        testInheritance("plugin-not-inherited-execution-override");
+    }
+
     /**
      * Check most classical urls inheritance: directory structure where parent 
POM in parent directory
      * and child directory == artifactId
diff --git 
a/compat/maven-model-builder/src/test/resources/poms/inheritance/plugin-not-inherited-child.xml
 
b/compat/maven-model-builder/src/test/resources/poms/inheritance/plugin-not-inherited-child.xml
new file mode 100644
index 0000000000..6ddc5757ac
--- /dev/null
+++ 
b/compat/maven-model-builder/src/test/resources/poms/inheritance/plugin-not-inherited-child.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<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 
https://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>child</artifactId>
+  <version>1-SNAPSHOT</version>
+</project>
diff --git 
a/compat/maven-model-builder/src/test/resources/poms/inheritance/plugin-not-inherited-execution-override-child.xml
 
b/compat/maven-model-builder/src/test/resources/poms/inheritance/plugin-not-inherited-execution-override-child.xml
new file mode 100644
index 0000000000..6ddc5757ac
--- /dev/null
+++ 
b/compat/maven-model-builder/src/test/resources/poms/inheritance/plugin-not-inherited-execution-override-child.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<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 
https://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>child</artifactId>
+  <version>1-SNAPSHOT</version>
+</project>
diff --git 
a/compat/maven-model-builder/src/test/resources/poms/inheritance/plugin-not-inherited-execution-override-expected.xml
 
b/compat/maven-model-builder/src/test/resources/poms/inheritance/plugin-not-inherited-execution-override-expected.xml
new file mode 100644
index 0000000000..6e2b31ce85
--- /dev/null
+++ 
b/compat/maven-model-builder/src/test/resources/poms/inheritance/plugin-not-inherited-execution-override-expected.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<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 
https://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>inheritance</groupId>
+  <artifactId>child</artifactId>
+  <version>1-SNAPSHOT</version>
+
+  <build>
+    <plugins>
+      <!-- MNG-2103: the plugin itself (version, identity) still reaches the 
child because
+           one of its executions carries its own inherited=true override; the 
other
+           execution (no override, falls back to the plugin-level 
inherited=false) is
+           correctly filtered out -->
+      <plugin>
+        <groupId>inheritance.plugin</groupId>
+        <artifactId>overridden</artifactId>
+        <version>1.0</version>
+        <executions>
+          <execution>
+            <id>inherited-execution</id>
+            <goals>
+              <goal>run</goal>
+            </goals>
+            <inherited>true</inherited>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git 
a/compat/maven-model-builder/src/test/resources/poms/inheritance/plugin-not-inherited-execution-override-parent.xml
 
b/compat/maven-model-builder/src/test/resources/poms/inheritance/plugin-not-inherited-execution-override-parent.xml
new file mode 100644
index 0000000000..d965becc24
--- /dev/null
+++ 
b/compat/maven-model-builder/src/test/resources/poms/inheritance/plugin-not-inherited-execution-override-parent.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<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 
https://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>inheritance</groupId>
+  <artifactId>parent</artifactId>
+  <version>1-SNAPSHOT</version>
+
+  <build>
+    <plugins>
+      <plugin>
+        <!-- MNG-2103: an execution with its own inherited=true overrides a 
plugin-level
+             inherited=false, so the whole plugin (including this execution) 
must still
+             reach the child -->
+        <groupId>inheritance.plugin</groupId>
+        <artifactId>overridden</artifactId>
+        <version>1.0</version>
+        <inherited>false</inherited>
+        <executions>
+          <execution>
+            <id>inherited-execution</id>
+            <inherited>true</inherited>
+            <goals>
+              <goal>run</goal>
+            </goals>
+          </execution>
+          <execution>
+            <id>not-inherited-execution</id>
+            <goals>
+              <goal>run</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git 
a/compat/maven-model-builder/src/test/resources/poms/inheritance/plugin-not-inherited-expected.xml
 
b/compat/maven-model-builder/src/test/resources/poms/inheritance/plugin-not-inherited-expected.xml
new file mode 100644
index 0000000000..cb8a68d644
--- /dev/null
+++ 
b/compat/maven-model-builder/src/test/resources/poms/inheritance/plugin-not-inherited-expected.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<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 
https://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>inheritance</groupId>
+  <artifactId>child</artifactId>
+  <version>1-SNAPSHOT</version>
+
+  <build>
+    <plugins>
+      <!-- MNG-6373: the parent's "not-inherited" plugin (inherited=false) 
must not appear here,
+           even though it declares an execution -->
+      <plugin>
+        <groupId>inheritance.plugin</groupId>
+        <artifactId>inherited</artifactId>
+        <version>2.0</version>
+        <executions>
+          <execution>
+            <id>inherited-execution</id>
+            <goals>
+              <goal>run</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git 
a/compat/maven-model-builder/src/test/resources/poms/inheritance/plugin-not-inherited-parent.xml
 
b/compat/maven-model-builder/src/test/resources/poms/inheritance/plugin-not-inherited-parent.xml
new file mode 100644
index 0000000000..a76f869e98
--- /dev/null
+++ 
b/compat/maven-model-builder/src/test/resources/poms/inheritance/plugin-not-inherited-parent.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<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 
https://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>inheritance</groupId>
+  <artifactId>parent</artifactId>
+  <version>1-SNAPSHOT</version>
+
+  <build>
+    <plugins>
+      <plugin>
+        <!-- MNG-6373: a plugin marked inherited=false must not reach child 
POMs,
+             even though it declares an execution -->
+        <groupId>inheritance.plugin</groupId>
+        <artifactId>not-inherited</artifactId>
+        <version>1.0</version>
+        <inherited>false</inherited>
+        <executions>
+          <execution>
+            <id>not-inherited-execution</id>
+            <goals>
+              <goal>run</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>inheritance.plugin</groupId>
+        <artifactId>inherited</artifactId>
+        <version>2.0</version>
+        <executions>
+          <execution>
+            <id>inherited-execution</id>
+            <goals>
+              <goal>run</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git 
a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultInheritanceAssembler.java
 
b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultInheritanceAssembler.java
index 74baa28024..ca79f25b7a 100644
--- 
a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultInheritanceAssembler.java
+++ 
b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultInheritanceAssembler.java
@@ -243,9 +243,15 @@ protected void mergePluginContainer_Plugins(
                         plugin = mergePlugin(plugin, element, sourceDominant, 
context);
                         plugin = withElementLocation(plugin, element);
 
-                        Object key = getPluginKey().apply(plugin);
-
-                        master.put(key, plugin);
+                        // a plugin marked inherited=false only reaches the 
child through an execution
+                        // whose own inherited flag overrides the plugin-level 
setting (MNG-2103); if no
+                        // execution survives that per-execution filtering, 
the plugin itself must not be
+                        // inherited either (MNG-6373), so only commit it once 
we know which case applies
+                        if (element.isInherited() || 
!plugin.getExecutions().isEmpty()) {
+                            Object key = getPluginKey().apply(plugin);
+
+                            master.put(key, plugin);
+                        }
                     }
                 }
 
diff --git 
a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultInheritanceAssemblerTest.java
 
b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultInheritanceAssemblerTest.java
index 97b0e7fba2..1cac557a45 100644
--- 
a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultInheritanceAssemblerTest.java
+++ 
b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultInheritanceAssemblerTest.java
@@ -132,6 +132,26 @@ void testPluginConfiguration() throws Exception {
         testInheritance("plugin-configuration");
     }
 
+    /**
+     * MNG-6373: a build plugin marked {@code inherited=false} must not reach 
child POMs,
+     * even when it declares an execution.
+     * @throws Exception
+     */
+    @Test
+    void testPluginNotInherited() throws Exception {
+        testInheritance("plugin-not-inherited");
+    }
+
+    /**
+     * MNG-2103: an execution's own {@code inherited=true} overrides a 
plugin-level
+     * {@code inherited=false}, so the whole plugin must still reach the child.
+     * @throws Exception
+     */
+    @Test
+    void testPluginNotInheritedWithInheritedExecutionOverride() throws 
Exception {
+        testInheritance("plugin-not-inherited-execution-override");
+    }
+
     public void testInheritance(String baseName) throws Exception {
         testInheritance(baseName, false);
         testInheritance(baseName, true);

Reply via email to