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

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


The following commit(s) were added to refs/heads/master by this push:
     new 9ca59a84f0 [MNG-6373] Forward-port: respect plugin-level 
inherited=false when the plugin has executions (#13994)
9ca59a84f0 is described below

commit 9ca59a84f0b1065aff3dff7638d552c637972095
Author: Arturo Bernal <[email protected]>
AuthorDate: Tue Nov 17 00:29:54 2026 +0100

    [MNG-6373] Forward-port: respect plugin-level inherited=false when the 
plugin has executions (#13994)
    
    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.
    
    Same fix as #13952 (maven-3.10.x), forward-ported to master's two
    copies of this class: the compat layer (compat/maven-model-builder) and
    the Maven 4 impl layer (impl/maven-impl). Only commit a 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).
    
    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 d165f12959..8cdb9c71e4 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 cf3e45267f..fae65727a6 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
@@ -65,6 +65,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 2f28c7c53e..47427aa3ef 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
@@ -254,9 +254,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 ecfc895a0c..89837590a2 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
@@ -134,6 +134,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

Reply via email to