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 ef1ce187aa [maven-4.0.x] Upgrade plugin dependencies 
(extra-enforcer-rules) in mvnup (#12108)
ef1ce187aa is described below

commit ef1ce187aa206b28dafdb9478c422cd672d0e8b4
Author: Guillaume Nodet <[email protected]>
AuthorDate: Tue May 19 21:56:45 2026 +0200

    [maven-4.0.x] Upgrade plugin dependencies (extra-enforcer-rules) in mvnup 
(#12108)
    
    * Upgrade extra-enforcer-rules in mvnup plugin dependency handling (#12051)
    
    extra-enforcer-rules versions before 1.4 use DependencyGraphBuilder
    .buildDependencyGraph(MavenProject, ArtifactFilter) which was removed
    in Maven 4. The mvnup plugin upgrade strategy now also checks and
    upgrades dependencies declared inside plugin configurations.
    
    Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
    
    * Fix test compilation: use domtrip API instead of JDOM in 
PluginUpgradeStrategyTest
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
    
    ---------
    
    Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
---
 .../invoker/mvnup/goals/PluginUpgradeStrategy.java | 56 +++++++++++++-
 .../mvnup/goals/PluginUpgradeStrategyTest.java     | 87 ++++++++++++++++++++++
 2 files changed, 141 insertions(+), 2 deletions(-)

diff --git 
a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnup/goals/PluginUpgradeStrategy.java
 
b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnup/goals/PluginUpgradeStrategy.java
index 64fc99e907..0f1a31406c 100644
--- 
a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnup/goals/PluginUpgradeStrategy.java
+++ 
b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnup/goals/PluginUpgradeStrategy.java
@@ -64,6 +64,8 @@
 
 import static 
eu.maveniverse.domtrip.maven.MavenPomElements.Elements.ARTIFACT_ID;
 import static eu.maveniverse.domtrip.maven.MavenPomElements.Elements.BUILD;
+import static 
eu.maveniverse.domtrip.maven.MavenPomElements.Elements.DEPENDENCIES;
+import static 
eu.maveniverse.domtrip.maven.MavenPomElements.Elements.DEPENDENCY;
 import static eu.maveniverse.domtrip.maven.MavenPomElements.Elements.GROUP_ID;
 import static eu.maveniverse.domtrip.maven.MavenPomElements.Elements.PARENT;
 import static eu.maveniverse.domtrip.maven.MavenPomElements.Elements.PLUGIN;
@@ -104,6 +106,12 @@ public class PluginUpgradeStrategy extends 
AbstractUpgradeStrategy {
             new PluginUpgrade(
                     DEFAULT_MAVEN_PLUGIN_GROUP_ID, "maven-failsafe-plugin", 
"3.5.2", MAVEN_4_COMPATIBILITY_REASON));
 
+    private static final List<PluginUpgrade> PLUGIN_DEPENDENCY_UPGRADES = 
List.of(new PluginUpgrade(
+            "org.codehaus.mojo",
+            "extra-enforcer-rules",
+            "1.4",
+            "Versions before 1.4 use a removed DependencyGraphBuilder API 
incompatible with Maven 4"));
+
     private Session session;
 
     @Inject
@@ -272,6 +280,7 @@ private boolean upgradePluginsInSection(
         return pluginsElement
                 .children(PLUGIN)
                 .map(pluginElement -> {
+                    boolean upgraded = false;
                     String groupId = getChildText(pluginElement, GROUP_ID);
                     String artifactId = getChildText(pluginElement, 
ARTIFACT_ID);
 
@@ -285,10 +294,13 @@ private boolean upgradePluginsInSection(
                         PluginUpgradeInfo upgrade = 
pluginUpgrades.get(pluginKey);
 
                         if (upgrade != null) {
-                            return upgradePluginVersion(pluginElement, 
upgrade, pomDocument, sectionName, context);
+                            upgraded = upgradePluginVersion(pluginElement, 
upgrade, pomDocument, sectionName, context);
                         }
                     }
-                    return false;
+
+                    upgraded |= upgradePluginDependencies(pluginElement, 
pomDocument, sectionName, context);
+
+                    return upgraded;
                 })
                 .reduce(false, Boolean::logicalOr);
     }
@@ -380,6 +392,46 @@ private boolean upgradePropertyVersion(
         return false;
     }
 
+    /**
+     * Upgrades plugin dependencies (e.g., extra-enforcer-rules inside 
maven-enforcer-plugin).
+     */
+    private boolean upgradePluginDependencies(
+            Element pluginElement, Document pomDocument, String sectionName, 
UpgradeContext context) {
+        Element dependenciesElement = 
pluginElement.child(DEPENDENCIES).orElse(null);
+        if (dependenciesElement == null) {
+            return false;
+        }
+
+        Map<String, PluginUpgradeInfo> depUpgrades = 
getPluginDependencyUpgradesMap();
+
+        return dependenciesElement
+                .children(DEPENDENCY)
+                .map(depElement -> {
+                    String groupId = getChildText(depElement, GROUP_ID);
+                    String artifactId = getChildText(depElement, ARTIFACT_ID);
+
+                    if (groupId != null && artifactId != null) {
+                        String depKey = groupId + ":" + artifactId;
+                        PluginUpgradeInfo upgrade = depUpgrades.get(depKey);
+
+                        if (upgrade != null) {
+                            return upgradePluginVersion(
+                                    depElement, upgrade, pomDocument, 
sectionName + "/plugin/dependencies", context);
+                        }
+                    }
+                    return false;
+                })
+                .reduce(false, Boolean::logicalOr);
+    }
+
+    private Map<String, PluginUpgradeInfo> getPluginDependencyUpgradesMap() {
+        return PLUGIN_DEPENDENCY_UPGRADES.stream()
+                .collect(Collectors.toMap(
+                        upgrade -> upgrade.groupId() + ":" + 
upgrade.artifactId(),
+                        upgrade ->
+                                new PluginUpgradeInfo(upgrade.groupId(), 
upgrade.artifactId(), upgrade.minVersion())));
+    }
+
     /**
      * Simple version comparison to check if current version is below minimum 
version.
      * This is a basic implementation that works for most Maven plugin 
versions.
diff --git 
a/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvnup/goals/PluginUpgradeStrategyTest.java
 
b/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvnup/goals/PluginUpgradeStrategyTest.java
index e63c364225..07347ca268 100644
--- 
a/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvnup/goals/PluginUpgradeStrategyTest.java
+++ 
b/impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvnup/goals/PluginUpgradeStrategyTest.java
@@ -534,6 +534,93 @@ void shouldNotUpgradeWhenPropertyNotFound() throws 
Exception {
         }
     }
 
+    @Nested
+    @DisplayName("Plugin Dependency Upgrades")
+    class PluginDependencyUpgradeTests {
+
+        @Test
+        @DisplayName("should upgrade extra-enforcer-rules dependency when 
below minimum")
+        void shouldUpgradeExtraEnforcerRulesDependency() throws Exception {
+            String pomXml = """
+                <?xml version="1.0" encoding="UTF-8"?>
+                <project xmlns="http://maven.apache.org/POM/4.0.0";>
+                    <modelVersion>4.0.0</modelVersion>
+                    <groupId>test</groupId>
+                    <artifactId>test</artifactId>
+                    <version>1.0.0</version>
+                    <build>
+                        <plugins>
+                            <plugin>
+                                <groupId>org.apache.maven.plugins</groupId>
+                                <artifactId>maven-enforcer-plugin</artifactId>
+                                <version>3.5.0</version>
+                                <dependencies>
+                                    <dependency>
+                                        <groupId>org.codehaus.mojo</groupId>
+                                        
<artifactId>extra-enforcer-rules</artifactId>
+                                        <version>1.0-beta-4</version>
+                                    </dependency>
+                                </dependencies>
+                            </plugin>
+                        </plugins>
+                    </build>
+                </project>
+                """;
+
+            Document document = Document.of(pomXml);
+            Map<Path, Document> pomMap = Map.of(Paths.get("pom.xml"), 
document);
+
+            UpgradeContext context = createMockContext();
+            UpgradeResult result = strategy.doApply(context, pomMap);
+
+            assertTrue(result.success(), "Plugin dependency upgrade should 
succeed");
+            assertTrue(result.modifiedCount() > 0, "Should have upgraded 
extra-enforcer-rules");
+
+            String xml = document.toXml();
+            assertTrue(xml.contains("<version>1.4</version>"), 
"extra-enforcer-rules should be upgraded to 1.4");
+            assertFalse(xml.contains("1.0-beta-4"), "Old version should be 
gone");
+        }
+
+        @Test
+        @DisplayName("should not upgrade extra-enforcer-rules when version is 
already sufficient")
+        void shouldNotUpgradeExtraEnforcerRulesWhenSufficient() throws 
Exception {
+            String pomXml = """
+                <?xml version="1.0" encoding="UTF-8"?>
+                <project xmlns="http://maven.apache.org/POM/4.0.0";>
+                    <modelVersion>4.0.0</modelVersion>
+                    <groupId>test</groupId>
+                    <artifactId>test</artifactId>
+                    <version>1.0.0</version>
+                    <build>
+                        <plugins>
+                            <plugin>
+                                <groupId>org.apache.maven.plugins</groupId>
+                                <artifactId>maven-enforcer-plugin</artifactId>
+                                <version>3.5.0</version>
+                                <dependencies>
+                                    <dependency>
+                                        <groupId>org.codehaus.mojo</groupId>
+                                        
<artifactId>extra-enforcer-rules</artifactId>
+                                        <version>1.8.0</version>
+                                    </dependency>
+                                </dependencies>
+                            </plugin>
+                        </plugins>
+                    </build>
+                </project>
+                """;
+
+            Document document = Document.of(pomXml);
+            Map<Path, Document> pomMap = Map.of(Paths.get("pom.xml"), 
document);
+
+            UpgradeContext context = createMockContext();
+            strategy.doApply(context, pomMap);
+
+            String xml = document.toXml();
+            assertTrue(xml.contains("1.8.0"), "Version 1.8.0 should be 
preserved");
+        }
+    }
+
     @Nested
     @DisplayName("Plugin Management")
     class PluginManagementTests {

Reply via email to