Skip to content

Commit 9c6d8d5

Browse files
TheHoundHannesWell
authored andcommitted
Include the classifier when creating an ArtifactKey from a org.apache.maven.artifact.Artifact to avoid issues with same dependency but different classifier & scope combinations
1 parent 172f6be commit 9c6d8d5

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
5+
<modelVersion>4.0.0</modelVersion>
6+
<groupId>com.example</groupId>
7+
<artifactId>test</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
10+
<dependencies>
11+
<dependency>
12+
<groupId>com.example</groupId>
13+
<artifactId>dependency-1</artifactId>
14+
<version>0.0.1-SNAPSHOT</version>
15+
<scope>compile</scope>
16+
</dependency>
17+
<dependency>
18+
<groupId>com.example</groupId>
19+
<artifactId>dependency-1</artifactId>
20+
<version>0.0.1-SNAPSHOT</version>
21+
<classifier>classifier</classifier>
22+
<scope>test</scope>
23+
</dependency>
24+
</dependencies>
25+
</project>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2023 Ben Gilbert and others
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License 2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*******************************************************************************/
10+
11+
package org.eclipse.m2e.core;
12+
13+
import java.util.List;
14+
import java.util.Set;
15+
16+
import org.eclipse.core.resources.IProject;
17+
import org.eclipse.core.resources.IncrementalProjectBuilder;
18+
import org.eclipse.core.resources.ResourcesPlugin;
19+
import org.eclipse.m2e.core.embedder.ArtifactRef;
20+
import org.eclipse.m2e.core.internal.MavenPluginActivator;
21+
import org.eclipse.m2e.core.project.IMavenProjectFacade;
22+
import org.eclipse.m2e.tests.common.AbstractMavenProjectTestCase;
23+
import org.junit.After;
24+
import org.junit.Assert;
25+
import org.junit.Test;
26+
27+
public class MavenDependencyTest extends AbstractMavenProjectTestCase {
28+
29+
@After
30+
public void clearWorkspace() throws Exception {
31+
for (IProject p : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
32+
p.delete(true, null);
33+
}
34+
}
35+
36+
@Test
37+
public void testArtifactsIncludeClassifier() throws Exception {
38+
IProject project = importProject("resources/projects/classifier/pom.xml");
39+
project.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
40+
waitForJobsToComplete(monitor);
41+
42+
IMavenProjectFacade facade = MavenPluginActivator.getDefault().getMavenProjectManagerImpl().create(project, monitor);
43+
Assert.assertNotNull(facade);
44+
45+
Set<ArtifactRef> artifacts = facade.getMavenProjectArtifacts();
46+
Assert.assertNotNull(artifacts);
47+
48+
List<String> portableRefs = artifacts.stream()
49+
.map(ref -> ref.artifactKey().toPortableString())
50+
.toList();
51+
// Confirm two different artifacts
52+
Assert.assertEquals("com.example:dependency-1:0.0.1-SNAPSHOT::", portableRefs.get(0));
53+
Assert.assertEquals("com.example:dependency-1:0.0.1-SNAPSHOT:classifier:", portableRefs.get(1));
54+
}
55+
56+
}

org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/ArtifactKey.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public record ArtifactKey(String groupId, String artifactId, String version, Str
2828
* Note that this constructor uses Artifact.getBaseVersion
2929
*/
3030
public ArtifactKey(Artifact a) {
31-
this(a.getGroupId(), a.getArtifactId(), a.getBaseVersion(), null);
31+
this(a.getGroupId(), a.getArtifactId(), a.getBaseVersion(), a.getClassifier());
3232
}
3333

3434
/**

0 commit comments

Comments
 (0)