Skip to content

Allow overriding a capability with a different capability version #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,16 @@ public CapabilityDefinitionRule(CapabilityDefinition definition) {
public final void execute(ComponentMetadataContext context) {
if (shouldApply(context.getDetails().getId())) {
context.getDetails().allVariants(variant -> {
variant.withCapabilities(capabilities -> capabilities.addCapability(
definition.getGroup(), definition.getCapabilityName(), getVersion(context.getDetails().getId())
));
variant.withCapabilities(capabilities -> {
// remove capability if it already exists so that it can be added back
// with a potentially different version
capabilities.removeCapability(
definition.getGroup(), definition.getCapabilityName()
);
capabilities.addCapability(
definition.getGroup(), definition.getCapabilityName(), getVersion(context.getDetails().getId())
);
});
additionalAdjustments(variant);
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package org.gradlex.jvm.dependency.conflict.test

import org.gradlex.jvm.dependency.conflict.test.fixture.GradleBuild
import spock.lang.Specification

import static org.gradlex.jvm.dependency.conflict.test.fixture.GradleBuild.GRADLE6_TEST

class CapabilityWithDifferentVersionsTest extends Specification {

@Delegate
GradleBuild build = new GradleBuild()

def "does not fail if capability is added several times with different versions"() {
given:
buildFile << """
plugins {
id("org.gradlex.jvm-dependency-conflict-detection") apply false
id("java-library")
}
repositories.mavenCentral()
dependencies.components {
withModule("com.google.guava:guava") {
allVariants {
withCapabilities {
addCapability("com.google.guava", "listenablefuture",
"9999.0-empty-to-avoid-conflict-with-guava")
}
}
}
}

apply(plugin = "org.gradlex.jvm-dependency-conflict-detection")

dependencies {
api("com.google.guava:guava:33.0.0-jre")
}

tasks.register("printJars") {
println(configurations.compileClasspath.get().files.joinToString("\\n") { it.name })
}
"""
if (GRADLE6_TEST) { configureEnvAttribute() }

expect:
printJars()
}

def "does not fail with empty listenable future dependency on the classpath"() {
given:
buildFile << """
plugins {
id("org.gradlex.jvm-dependency-conflict-resolution")
id("java-library")
}
tasks.withType<JavaCompile>().configureEach {
options.release.set(17)
}
repositories.mavenCentral()
dependencies {
implementation(platform("com.google.cloud:spring-cloud-gcp-dependencies:5.2.0"))
implementation("com.google.cloud:spring-cloud-gcp-starter-bigquery")
}

tasks.register("printJars") {
println(configurations.compileClasspath.get().files.joinToString("\\n") { it.name })
}
"""
if (GRADLE6_TEST) { configureEnvAttribute() }

expect:
printJars()
}

void configureEnvAttribute() {
buildFile << """
val envAttribute = Attribute.of("org.gradle.jvm.environment", String::class.java)
configurations.compileClasspath {
attributes.attribute(envAttribute, "standard-jvm")
}
"""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ class GuavaClasspathTest extends Specification {

static allGuavaVersions() {
[
['33.2.0', 'jre' , [errorProne: '2.26.1', j2objc: '3.0.0', jsr305: '3.0.2', checker: '3.42.0', failureaccess: '1.0.2']],
['33.2.0', 'android', [errorProne: '2.26.1', j2objc: '3.0.0', jsr305: '3.0.2', checker: '3.42.0', failureaccess: '1.0.2']],
['33.1.0', 'jre' , [errorProne: '2.26.1', j2objc: '3.0.0', jsr305: '3.0.2', checker: '3.42.0', failureaccess: '1.0.2']],
['33.1.0', 'android', [errorProne: '2.26.1', j2objc: '3.0.0', jsr305: '3.0.2', checker: '3.42.0', failureaccess: '1.0.2']],
['33.0.0', 'jre' , [errorProne: '2.23.0', j2objc: '2.8', jsr305: '3.0.2', checker: '3.41.0', failureaccess: '1.0.2']],
['33.0.0', 'android', [errorProne: '2.23.0', j2objc: '2.8', jsr305: '3.0.2', checker: '3.41.0', failureaccess: '1.0.2']],
['32.1.3', 'jre' , [errorProne: '2.21.1', j2objc: '2.8', jsr305: '3.0.2', checker: '3.37.0', failureaccess: '1.0.1']],
['32.1.3', 'android', [errorProne: '2.21.1', j2objc: '2.8', jsr305: '3.0.2', checker: '3.37.0', failureaccess: '1.0.1']],
['32.1.2', 'jre' , [errorProne: '2.18.0', j2objc: '2.8', jsr305: '3.0.2', checker: '3.33.0', failureaccess: '1.0.1']],
['32.1.2', 'android', [errorProne: '2.18.0', j2objc: '2.8', jsr305: '3.0.2', checker: '3.33.0', failureaccess: '1.0.1']],
['32.1.1', 'jre' , [errorProne: '2.18.0', j2objc: '2.8', jsr305: '3.0.2', checker: '3.33.0', failureaccess: '1.0.1']],
['32.1.1', 'android', [errorProne: '2.18.0', j2objc: '2.8', jsr305: '3.0.2', checker: '3.33.0', failureaccess: '1.0.1']],
['32.0.1', 'jre' , [errorProne: '2.18.0', j2objc: '2.8', jsr305: '3.0.2', checker: '3.33.0', failureaccess: '1.0.1']],
Expand Down Expand Up @@ -111,12 +121,12 @@ class GuavaClasspathTest extends Specification {
result.add([it[0], it[1], it[2], 'standard-jvm', 'runtimeClasspath'])
}
}
if (System.getProperty("gradleVersionUnderTest") == "7.5.1") {
if (System.getProperty("gradleVersionUnderTest") == "7.6.4") {
// only do all permutations for one Gradle version
return result
}
// reduced amount of permutations
return result.subList(0, 32)
return result.subList(0, 80)
}

@Unroll
Expand Down Expand Up @@ -160,7 +170,7 @@ class GuavaClasspathTest extends Specification {
"""

expect:
expectedClasspath(guavaVersion, jvmEnv, classpath, dependencyVersions) == printJars().output.split('\n') as Set
expectedClasspath(guavaVersion, jvmEnv, classpath, dependencyVersions) == printJars().output.split('\n') as TreeSet

where:
[guavaVersion, versionSuffix, dependencyVersions, jvmEnv, classpath] << allGuavaCombinations(true)
Expand All @@ -169,7 +179,7 @@ class GuavaClasspathTest extends Specification {
Set<String> expectedClasspath(String guavaVersion, String jvmEnv, String classpath, Map<String, String> dependencyVersions) {
int majorGuavaVersion = guavaVersion.substring(0, 2) as Integer
String jarSuffix = majorGuavaVersion < 22 ? '' : jvmEnv == 'android' ? 'android' : (guavaVersion == '22.0' || guavaVersion == '23.0') ? '' : 'jre'
Set<String> result = ["guava-${guavaVersion}${jarSuffix? '-' : ''}${jarSuffix}.jar"]
Set<String> result = ["guava-${guavaVersion}${jarSuffix? '-' : ''}${jarSuffix}.jar"] as TreeSet
if (dependencyVersions.failureaccess) {
result += "failureaccess-${dependencyVersions.failureaccess}.jar"
}
Expand Down
Loading