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 6d313829 Fix #532: include classifier and extension in convergence key
6d313829 is described below
commit 6d313829d2ae3e4b2af4057b7f5a0bdc5b0c0386
Author: Arturo Bernal <[email protected]>
AuthorDate: Thu Oct 29 14:10:05 2026 +0100
Fix #532: include classifier and extension in convergence key
DependencyVersionMap.constructKey(Artifact) grouped dependencies for
the convergence check by groupId:artifactId alone. Two artifacts that
share groupId:artifactId but differ by classifier or extension -- for
example platform-specific native jars published under the same
groupId:artifactId with a different classifier per OS/arch -- are
different files that can legitimately carry different versions, but
got bucketed into the same convergence group and reported as a
version conflict.
constructKey now includes classifier and extension, matching how
Maven identifies a specific artifact. Added DependencyConvergenceTest
covering both cases: different classifiers with different versions no
longer conflict, while a real same-classifier version mismatch still
does.
---
.../rules/dependency/DependencyVersionMap.java | 3 +-
.../dependency/DependencyConvergenceTest.java | 88 ++++++++++++++++++++++
.../rules/utils/DependencyNodeBuilder.java | 9 ++-
3 files changed, 98 insertions(+), 2 deletions(-)
diff --git
a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/dependency/DependencyVersionMap.java
b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/dependency/DependencyVersionMap.java
index 29fcbbc6..864b9747 100644
---
a/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/dependency/DependencyVersionMap.java
+++
b/enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/dependency/DependencyVersionMap.java
@@ -69,7 +69,8 @@ class DependencyVersionMap implements DependencyVisitor,
ParentNodeProvider {
}
private String constructKey(Artifact artifact) {
- return artifact.getGroupId() + ":" + artifact.getArtifactId();
+ return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" +
artifact.getClassifier() + ":"
+ + artifact.getExtension();
}
public void addDependency(DependencyNode node) {
diff --git
a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/dependency/DependencyConvergenceTest.java
b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/dependency/DependencyConvergenceTest.java
new file mode 100644
index 00000000..3ba3cd86
--- /dev/null
+++
b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/dependency/DependencyConvergenceTest.java
@@ -0,0 +1,88 @@
+/*
+ * 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.
+ */
+package org.apache.maven.enforcer.rules.dependency;
+
+import org.apache.maven.enforcer.rule.api.EnforcerLogger;
+import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
+import org.apache.maven.enforcer.rules.utils.DependencyNodeBuilder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class DependencyConvergenceTest {
+
+ @Mock
+ private ResolverUtil resolverUtil;
+
+ @InjectMocks
+ private DependencyConvergence rule;
+
+ @Test
+ void differentClassifiersWithDifferentVersionsDoNotConflict() throws
Exception {
+ rule.setLog(mock(EnforcerLogger.class));
+
+ when(resolverUtil.resolveTransitiveDependenciesVerbose(anyList()))
+ .thenReturn(new DependencyNodeBuilder()
+ .withType(DependencyNodeBuilder.Type.POM)
+ .withChildNode(new DependencyNodeBuilder()
+ .withArtifactId("native-lib")
+ .withClassifier("linux-x86_64")
+ .withVersion("1.0.0")
+ .build())
+ .withChildNode(new DependencyNodeBuilder()
+ .withArtifactId("native-lib")
+ .withClassifier("osx-aarch_64")
+ .withVersion("2.0.0")
+ .build())
+ .build());
+
+ assertThatCode(rule::execute).doesNotThrowAnyException();
+ }
+
+ @Test
+ void sameClassifierWithDifferentVersionsStillConflicts() throws Exception {
+ rule.setLog(mock(EnforcerLogger.class));
+
+ when(resolverUtil.resolveTransitiveDependenciesVerbose(anyList()))
+ .thenReturn(new DependencyNodeBuilder()
+ .withType(DependencyNodeBuilder.Type.POM)
+ .withChildNode(new DependencyNodeBuilder()
+ .withArtifactId("childA")
+ .withVersion("1.0.0")
+ .build())
+ .withChildNode(new DependencyNodeBuilder()
+ .withArtifactId("childA")
+ .withVersion("2.0.0")
+ .build())
+ .build());
+
+ assertThatCode(rule::execute)
+ .isInstanceOf(EnforcerRuleException.class)
+
.hasMessageContaining("default-group:childA:jar:classifier:1.0.0")
+
.hasMessageContaining("default-group:childA:jar:classifier:2.0.0");
+ }
+}
diff --git
a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/utils/DependencyNodeBuilder.java
b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/utils/DependencyNodeBuilder.java
index 4d586c29..3c8f2349 100644
---
a/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/utils/DependencyNodeBuilder.java
+++
b/enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/utils/DependencyNodeBuilder.java
@@ -63,6 +63,8 @@ public class DependencyNodeBuilder {
private String premanagedVersion;
+ private String classifier;
+
private Type type;
private String scope;
@@ -91,6 +93,11 @@ public class DependencyNodeBuilder {
return this;
}
+ public DependencyNodeBuilder withClassifier(String val) {
+ classifier = val;
+ return this;
+ }
+
public DependencyNodeBuilder withType(Type val) {
type = val;
return this;
@@ -115,7 +122,7 @@ public class DependencyNodeBuilder {
Artifact artifact = new DefaultArtifact(
ofNullable(groupId).orElse("default-group"),
ofNullable(artifactId).orElse("default-artifact"),
- "classifier",
+ ofNullable(classifier).orElse("classifier"),
ofNullable(type).map(Type::asString).orElse("pom"),
ofNullable(version).orElse("default-version"),
ofNullable(type).orElse(Type.JAR).asArtifactType());