-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Description
@jjohannes, thanks for offering to have a look and fill in what I'm missing. Here's what I've come up with. You can post suggestions for edits, or you can copy the whole thing and post a comment with your full, revised version.
Gradle Module Metadata
The Gradle team has contributed a metadata file for Guava. If you use Gradle 6 or higher, you will see better handling of two kinds of dependency conflicts:
Selecting the appropriate flavor
When Gradle automatically selects the newest version of Guava in your dependency graph, it will now also select the appropriate flavor (-android
or -jre
) based on whether you project targets Android or not. For example, if you depend on 32.1.0-android and 30.0-jre, Gradle will select 32.1.0-jre. This is the version most likely to be compatible with all your dependencies.
If you need to override Gradle's choice, you can TODO: something like the following? I thought I'd convinced myself that I understood which part(s) of it were necessary, but now I'm confused again, sorry:
guava/integration-tests/gradle/build.gradle.kts
Lines 145 to 167 in ce78fc6
dependencies { | |
constraints { | |
"api"("com.google.guava:guava") { | |
attributes { | |
// if the Gradle version is 7+, you can use | |
// TargetJvmEnvironment.TARGET_JVM_ENVIRONMENT_ATTRIBUTE | |
attribute(Attribute.of("org.gradle.jvm.environment", String::class.java), "android") | |
} | |
} | |
} | |
} | |
configurations.all { | |
resolutionStrategy.capabilitiesResolution { | |
withCapability("com.google.guava:guava") { | |
candidates | |
.find { | |
val variantName = it.javaClass.getDeclaredMethod("getVariantName") | |
(variantName.invoke(it) as String).contains("android") | |
} | |
?.apply { select(this) } | |
} | |
} | |
} |
Reporting dependencies that overlap with Guava
If your dependency graph contains the very old google-collections
or the hacky listenablefuture
, Gradle will now report that those libraries contain duplicates of Guava classes. When this happens, you'll need to tell Gradle to select Guava:
configurations.all {
resolutionStrategy.capabilitiesResolution.withCapability("com.google.collections:google-collections") {
select("com.google.guava:guava:0")
}
// and/or
resolutionStrategy.capabilitiesResolution.withCapability("com.google.guava:listenablefuture") {
select("com.google.guava:guava:0")
}
}
(I could also mention that we'll now omit j2objc-annotations
from the runtime classpath, but I think we may be better off focusing on the bigger changes, since there's plenty to discuss. Let me know if you disagree.)