This is an automated email from the ASF dual-hosted git repository.
slawekjaranowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-enforcer.git
The following commit(s) were added to refs/heads/master by this push:
new 9466258a Fix #870: resolve profile plugin expressions in
RequirePluginVersions
9466258a is described below
commit 9466258a6571a1b233e559917ff9774452a8a1c4
Author: Arturo Bernal <[email protected]>
AuthorDate: Tue Nov 17 19:48:35 2026 +0100
Fix #870: resolve profile plugin expressions in RequirePluginVersions
getProfilePlugins(MavenProject) collected a profile's build plugins
straight from the model without resolving property expressions,
while the plugin entries it's later matched against (via
getAllPluginEntries()'s own getProfilePlugins(List, Profile)
overload) are resolved through EnforcerRuleUtils.resolvePlugins().
A profile plugin declared with a property-based artifactId therefore
never matched its resolved counterpart, and the rule reported it as
missing a version even when one was correctly declared.
Claude-Session: https://claude.ai/code/session_01BrsHTdDq7PD1DoqeA9vs66
---
.../enforcer/rules/RequirePluginVersions.java | 5 +++-
.../enforcer/rules/TestRequirePluginVersions.java | 29 ++++++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
diff --git
a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/RequirePluginVersions.java
b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/RequirePluginVersions.java
index 86994926..da52afd2 100644
---
a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/RequirePluginVersions.java
+++
b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/RequirePluginVersions.java
@@ -420,7 +420,10 @@ public final class RequirePluginVersions extends
AbstractStandardEnforcerRule {
if (b != null) {
List<Plugin> plugins = b.getPlugins();
if (plugins != null) {
- result.addAll(plugins);
+ // resolve groupId/artifactId/version expressions,
same as getAllPluginEntries()'s
+ // profile plugins below: otherwise a property-based
artifactId here never matches
+ // the resolved artifactId isMatchingPlugin() compares
it against.
+ result.addAll(utils.resolvePlugins(plugins));
}
}
}
diff --git
a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/TestRequirePluginVersions.java
b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/TestRequirePluginVersions.java
index 39dd6729..11295440 100644
---
a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/TestRequirePluginVersions.java
+++
b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/TestRequirePluginVersions.java
@@ -20,6 +20,7 @@ package org.apache.maven.enforcer.rules;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -32,7 +33,9 @@ import
org.apache.maven.enforcer.rules.utils.ExpressionEvaluator;
import org.apache.maven.enforcer.rules.utils.PluginWrapper;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.DefaultLifecycles;
+import org.apache.maven.model.BuildBase;
import org.apache.maven.model.Plugin;
+import org.apache.maven.model.Profile;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.project.MavenProject;
@@ -52,6 +55,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
+import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.when;
@@ -244,6 +248,31 @@ class TestRequirePluginVersions {
assertTrue(rule.hasValidVersionSpecified(source, pluginWrappers));
}
+ /**
+ * Test that plugins declared in active profiles with a property-based
artifactId are resolved before being
+ * matched against the (already-resolved) plugin entries gathered
elsewhere, instead of being compared by their
+ * raw, unresolved artifactId (see issue #870 / MENFORCER-518).
+ */
+ @Test
+ void testGetProfilePluginsResolvesPropertyBasedArtifactId() {
+ Plugin unresolved = EnforcerTestUtils.newPlugin("group",
"${myArtifactIdProp}", "1.0");
+ Plugin resolved = EnforcerTestUtils.newPlugin("group",
"real-artifact", "1.0");
+
+ BuildBase build = new BuildBase();
+ build.setPlugins(Collections.singletonList(unresolved));
+
+ Profile profile = new Profile();
+ profile.setBuild(build);
+
+
when(project.getActiveProfiles()).thenReturn(Collections.singletonList(profile));
+
when(utils.resolvePlugins(anyList())).thenReturn(Collections.singletonList(resolved));
+
+ Set<Plugin> result = rule.getProfilePlugins(project);
+
+ assertEquals(1, result.size());
+ assertEquals("real-artifact",
result.iterator().next().getArtifactId());
+ }
+
/**
* Test get additional plugins null.
*