Skip to content

Commit daae339

Browse files
authored
[MRESOLVER-668] Don't default the scope of managed dependencies to 'compile' (#50)
If a scope isn't defined in a managed dependency, the scope specified in the dependency section is used for resolving transitive dependencies. I thought that letting the maven-resolver classes do all defaulting would have worked, but without defaulting the scope of the other dependencies created by ConverterUtils.toDependency, ResolveTest.testResolveNestedDependencyCollections() fails. Removing this defaulting still seems like it might be the right thing to do, but I'm not pulling on this thread. I don't know what it is attached to. --- https://issues.apache.org/jira/browse/MRESOLVER-668
1 parent 867d134 commit daae339

6 files changed

Lines changed: 44 additions & 4 deletions

File tree

src/main/java/org/apache/maven/resolver/internal/ant/AntRepoSys.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ private void populateCollectRequest(
654654
dependency.addExclusion(exclusion);
655655
}
656656
collectRequest.addManagedDependency(
657-
ConverterUtils.toDependency(dependency, globalExclusions, session));
657+
ConverterUtils.toManagedDependency(dependency, globalExclusions, session));
658658
}
659659
}
660660

src/main/java/org/apache/maven/resolver/internal/ant/ConverterUtils.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Map;
2727
import java.util.Properties;
2828

29+
import org.apache.commons.lang3.ObjectUtils;
2930
import org.apache.maven.resolver.internal.ant.types.Authentication;
3031
import org.apache.maven.resolver.internal.ant.types.Dependency;
3132
import org.apache.maven.resolver.internal.ant.types.Exclusion;
@@ -82,6 +83,16 @@ public static org.eclipse.aether.repository.Authentication toAuthentication(Auth
8283

8384
public static org.eclipse.aether.graph.Dependency toDependency(
8485
Dependency dependency, List<Exclusion> exclusions, RepositorySystemSession session) {
86+
String scope = dependency.getScope();
87+
return new org.eclipse.aether.graph.Dependency(
88+
toArtifact(dependency, session.getArtifactTypeRegistry()),
89+
ObjectUtils.isEmpty(scope) ? "compile" : scope,
90+
false,
91+
toExclusions(dependency.getExclusions(), exclusions));
92+
}
93+
94+
public static org.eclipse.aether.graph.Dependency toManagedDependency(
95+
Dependency dependency, List<Exclusion> exclusions, RepositorySystemSession session) {
8596
return new org.eclipse.aether.graph.Dependency(
8697
toArtifact(dependency, session.getArtifactTypeRegistry()),
8798
dependency.getScope(),

src/main/java/org/apache/maven/resolver/internal/ant/types/Dependency.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public String getScope() {
188188
if (isReference()) {
189189
return getRef().getScope();
190190
}
191-
return (scope != null) ? scope : "compile";
191+
return (scope != null) ? scope : "";
192192
}
193193

194194
public void setScope(String scope) {

src/test/java/org/apache/maven/resolver/internal/ant/ResolveTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,23 @@ public void testResolveTransitiveDependencyManagement() {
177177
prop,
178178
allOf(containsString("apiguardian-api"), endsWith("apiguardian-api-1.1.1.jar")));
179179
}
180+
181+
@Test
182+
public void testResolveTransitiveDependencyManagementTestScope() {
183+
executeTarget("testResolveTransitiveDependencyManagementTestScope");
184+
185+
String prop = getProject().getProperty("test.compile.resolve.path.org.slf4j:slf4j-api:jar");
186+
assertThat("slf4j-api was not resolved as a property", prop, notNullValue());
187+
assertThat(
188+
"slf4j-api was not resolved to default local repository",
189+
prop,
190+
allOf(containsString("slf4j-api"), endsWith("slf4j-api-2.0.6.jar")));
191+
192+
prop = getProject().getProperty("test.resolve.path.org.apiguardian:apiguardian-api:jar");
193+
assertThat("apiguardian-api was not resolved as a property", prop, notNullValue());
194+
assertThat(
195+
"apiguardian-api was not resolved to default local repository",
196+
prop,
197+
allOf(containsString("apiguardian-api"), endsWith("apiguardian-api-1.1.1.jar")));
198+
}
180199
}

src/test/java/org/apache/maven/resolver/internal/ant/types/DependencyTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void testSetCoordsGidAidVer() {
4040
assertEquals("ver", dep.getVersion());
4141
assertEquals("jar", dep.getType());
4242
assertEquals("", dep.getClassifier());
43-
assertEquals("compile", dep.getScope());
43+
assertEquals("", dep.getScope());
4444
}
4545

4646
@Test

src/test/resources/ant/Resolve/ant.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,18 @@
122122
<target name="testResolveTransitiveDependencyManagement">
123123
<repo:pom file="${project.dir}/transitive-depmgt-pom.xml"/>
124124
<repo:resolve>
125-
<properties prefix="test.resolve.path" classpath="compile"/>
125+
<properties prefix="test.resolve.path" classpath="test"/>
126126
</repo:resolve>
127127
</target>
128128

129+
<target name="testResolveTransitiveDependencyManagementTestScope">
130+
<repo:pom file="${project.dir}/transitive-depmgt-pom.xml"/>
131+
<repo:resolve>
132+
<properties prefix="test.compile.resolve.path" scopes="compile"/>
133+
<properties prefix="test.compile.resolve.classpath" classpath="compile"/>
134+
<properties prefix="test.resolve.path" scopes="test"/>
135+
<properties prefix="test.resolve.classpath" classpath="test"/>
136+
</repo:resolve>
137+
</target>
138+
129139
</project>

0 commit comments

Comments
 (0)