@@ -4,15 +4,18 @@ import org.gradlex.jvm.dependency.conflict.test.fixture.GradleBuild
44
55class ModifyDependenciesTest extends AbstractPatchTest {
66
7- def " can remove dependencies" () {
8- given :
7+ def setup () {
98 if (GradleBuild . GRADLE6_TEST ) {
109 buildFile << """
11- configurations.compileClasspath {
10+ configurations.configureEach {
1211 attributes.attribute(Attribute.of("org.gradle.jvm.environment", String::class.java), "standard-jvm")
1312 }
1413 """
1514 }
15+ }
16+
17+ def " can remove dependencies" () {
18+ given :
1619 buildFile << """
1720 jvmDependencyConflicts {
1821 patch {
@@ -67,7 +70,7 @@ runtimeClasspath - Runtime classpath of source set 'main'.
6770'''
6871 }
6972
70- def " can reduce dependency scope to compile only" () {
73+ def " can reduce dependency scope to compile only for standard variants " () {
7174 given :
7275 buildFile << """
7376 jvmDependencyConflicts {
@@ -93,6 +96,41 @@ compileClasspath - Compile classpath for source set 'main'.
9396runtimeClasspath - Runtime classpath of source set 'main'.
9497\\ --- org.apache.commons:commons-text:1.11.0
9598
99+ '''
100+ }
101+
102+ def " can reduce dependency scope to compile only for non-standard variants" () {
103+ given :
104+ buildFile << """
105+ jvmDependencyConflicts {
106+ patch {
107+ module("com.google.guava:guava") {
108+ reduceToCompileOnlyApiDependency("com.google.errorprone:error_prone_annotations")
109+ reduceToCompileOnlyApiDependency("org.jspecify:jspecify")
110+ reduceToCompileOnlyApiDependency("com.google.j2objc:j2objc-annotations")
111+ }
112+ }
113+ }
114+ dependencies {
115+ implementation("com.google.guava:guava:33.4.8-jre")
116+ }
117+ """
118+
119+ expect : ' All dependencies are present on the compile classpath'
120+ dependenciesCompile(). output. contains '''
121+ compileClasspath - Compile classpath for source set 'main'.
122+ \\ --- com.google.guava:guava:33.4.8-jre
123+ +--- com.google.guava:failureaccess:1.0.3
124+ +--- org.jspecify:jspecify:1.0.0
125+ +--- com.google.errorprone:error_prone_annotations:2.36.0
126+ \\ --- com.google.j2objc:j2objc-annotations:3.0.0
127+ '''
128+
129+ and : ' Annotation libraries are not present on the runtime classpath'
130+ dependenciesRuntime(). output. contains '''
131+ runtimeClasspath - Runtime classpath of source set 'main'.
132+ \\ --- com.google.guava:guava:33.4.8-jre
133+ \\ --- com.google.guava:failureaccess:1.0.3
96134'''
97135 }
98136
0 commit comments