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 4f3ee14c86 Fix #12087: add surefire and failsafe plugins to
PluginUpgradeStrategy (#12089)
4f3ee14c86 is described below
commit 4f3ee14c86149abe1903b7a910fc43f1a818bc0d
Author: Guillaume Nodet <[email protected]>
AuthorDate: Tue May 19 16:27:09 2026 +0200
Fix #12087: add surefire and failsafe plugins to PluginUpgradeStrategy
(#12089)
Older versions of maven-surefire-plugin and maven-failsafe-plugin
(e.g. 3.1.2) are incompatible with Maven 4, failing with
IllegalStateException in MojoExecutionScopeModule. Add both plugins
with minimum version 3.5.2 so mvnup upgrades them automatically.
Co-authored-by: Claude Opus 4.6 <[email protected]>
---
.../invoker/mvnup/goals/PluginUpgradeStrategy.java | 12 +++-
.../mvnup/goals/PluginUpgradeStrategyTest.java | 84 ++++++++++++++++++++++
2 files changed, 95 insertions(+), 1 deletion(-)
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 0dcb39883c..64fc99e907 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
@@ -98,7 +98,11 @@ public class PluginUpgradeStrategy extends
AbstractUpgradeStrategy {
DEFAULT_MAVEN_PLUGIN_GROUP_ID,
"maven-remote-resources-plugin",
"3.0.0",
- MAVEN_4_COMPATIBILITY_REASON));
+ MAVEN_4_COMPATIBILITY_REASON),
+ new PluginUpgrade(
+ DEFAULT_MAVEN_PLUGIN_GROUP_ID, "maven-surefire-plugin",
"3.5.2", MAVEN_4_COMPATIBILITY_REASON),
+ new PluginUpgrade(
+ DEFAULT_MAVEN_PLUGIN_GROUP_ID, "maven-failsafe-plugin",
"3.5.2", MAVEN_4_COMPATIBILITY_REASON));
private Session session;
@@ -246,6 +250,12 @@ private Map<String, PluginUpgradeInfo>
getPluginUpgradesMap() {
upgrades.put(
DEFAULT_MAVEN_PLUGIN_GROUP_ID +
":maven-remote-resources-plugin",
new PluginUpgradeInfo(DEFAULT_MAVEN_PLUGIN_GROUP_ID,
"maven-remote-resources-plugin", "3.0.0"));
+ upgrades.put(
+ DEFAULT_MAVEN_PLUGIN_GROUP_ID + ":maven-surefire-plugin",
+ new PluginUpgradeInfo(DEFAULT_MAVEN_PLUGIN_GROUP_ID,
"maven-surefire-plugin", "3.5.2"));
+ upgrades.put(
+ DEFAULT_MAVEN_PLUGIN_GROUP_ID + ":maven-failsafe-plugin",
+ new PluginUpgradeInfo(DEFAULT_MAVEN_PLUGIN_GROUP_ID,
"maven-failsafe-plugin", "3.5.2"));
return upgrades;
}
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 3a135df160..74cb3788c1 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
@@ -311,6 +311,84 @@ void shouldUpgradePluginWithPropertyVersion() throws
Exception {
assertEquals("3.5.0", version);
}
+ @Test
+ @DisplayName("should upgrade surefire plugin when below minimum")
+ void shouldUpgradeSurefirePluginWhenBelowMinimum() 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-surefire-plugin</artifactId>
+ <version>3.1.2</version>
+ </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 upgrade should succeed");
+ assertTrue(result.modifiedCount() > 0, "Should have upgraded
maven-surefire-plugin");
+
+ Editor editor = new Editor(document);
+ Element root = editor.root();
+ String version = root.path("build", "plugins", "plugin", "version")
+ .map(Element::textContentTrimmed)
+ .orElse(null);
+ assertEquals("3.5.2", version);
+ }
+
+ @Test
+ @DisplayName("should upgrade failsafe plugin when below minimum")
+ void shouldUpgradeFailsafePluginWhenBelowMinimum() 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-failsafe-plugin</artifactId>
+ <version>3.1.2</version>
+ </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 upgrade should succeed");
+ assertTrue(result.modifiedCount() > 0, "Should have upgraded
maven-failsafe-plugin");
+
+ Editor editor = new Editor(document);
+ Element root = editor.root();
+ String version = root.path("build", "plugins", "plugin", "version")
+ .map(Element::textContentTrimmed)
+ .orElse(null);
+ assertEquals("3.5.2", version);
+ }
+
@Test
@DisplayName("should not upgrade when version is already higher")
void shouldNotUpgradeWhenVersionAlreadyHigher() throws Exception {
@@ -534,9 +612,15 @@ void shouldHavePredefinedPluginUpgrades() throws Exception
{
upgrades.stream().anyMatch(upgrade ->
"maven-compiler-plugin".equals(upgrade.artifactId()));
boolean hasExecPlugin =
upgrades.stream().anyMatch(upgrade ->
"maven-exec-plugin".equals(upgrade.artifactId()));
+ boolean hasSurefirePlugin =
+ upgrades.stream().anyMatch(upgrade ->
"maven-surefire-plugin".equals(upgrade.artifactId()));
+ boolean hasFailsafePlugin =
+ upgrades.stream().anyMatch(upgrade ->
"maven-failsafe-plugin".equals(upgrade.artifactId()));
assertTrue(hasCompilerPlugin, "Should include
maven-compiler-plugin upgrade");
assertTrue(hasExecPlugin, "Should include maven-exec-plugin
upgrade");
+ assertTrue(hasSurefirePlugin, "Should include
maven-surefire-plugin upgrade");
+ assertTrue(hasFailsafePlugin, "Should include
maven-failsafe-plugin upgrade");
}
@Test