Skip to content
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

Remove annotation-only Jars from runtime classpath (in Gradle) #6606

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
90 changes: 20 additions & 70 deletions guava/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@
"requires": "1.0.2"
}
},
{
"group": "com.google.guava",
"module": "listenablefuture",
"version": {
"requires": "9999.0-empty-to-avoid-conflict-with-guava"
}
},
{
"group": "com.google.code.findbugs",
"module": "jsr305",
Expand Down Expand Up @@ -85,6 +78,11 @@
"group": "com.google.collections",
"name": "google-collections",
"version": "${pom.version}"
},
{
"group": "com.google.guava",
"name": "listenablefuture",
"version": "1.0"
}
]
},
Expand All @@ -105,34 +103,6 @@
"version": {
"requires": "1.0.2"
}
},
{
"group": "com.google.guava",
"module": "listenablefuture",
"version": {
"requires": "9999.0-empty-to-avoid-conflict-with-guava"
}
},
{
"group": "com.google.code.findbugs",
"module": "jsr305",
"version": {
"requires": "${jsr305.version}"
}
},
{
"group": "org.checkerframework",
"module": "checker-qual",
"version": {
"requires": "${checker.version}"
}
},
{
"group": "com.google.errorprone",
"module": "error_prone_annotations",
"version": {
"requires": "${errorprone.version}"
}
}
],
"files": [
Expand All @@ -151,6 +121,11 @@
"group": "com.google.collections",
"name": "google-collections",
"version": "${pom.version}"
},
{
"group": "com.google.guava",
"name": "listenablefuture",
"version": "1.0"
}
]
},
Expand All @@ -172,13 +147,6 @@
"requires": "1.0.2"
}
},
{
"group": "com.google.guava",
"module": "listenablefuture",
"version": {
"requires": "9999.0-empty-to-avoid-conflict-with-guava"
}
},
{
"group": "com.google.code.findbugs",
"module": "jsr305",
Expand Down Expand Up @@ -224,6 +192,11 @@
"group": "com.google.collections",
"name": "google-collections",
"version": "${pom.version}"
},
{
"group": "com.google.guava",
"name": "listenablefuture",
"version": "1.0"
}
]
},
Expand All @@ -244,34 +217,6 @@
"version": {
"requires": "1.0.2"
}
},
{
"group": "com.google.guava",
"module": "listenablefuture",
"version": {
"requires": "9999.0-empty-to-avoid-conflict-with-guava"
}
},
{
"group": "com.google.code.findbugs",
"module": "jsr305",
"version": {
"requires": "${jsr305.version}"
}
},
{
"group": "org.checkerframework",
"module": "checker-qual",
"version": {
"requires": "${checker.version}"
}
},
{
"group": "com.google.errorprone",
"module": "error_prone_annotations",
"version": {
"requires": "${errorprone.version}"
}
}
],
"files": [
Expand All @@ -290,6 +235,11 @@
"group": "com.google.collections",
"name": "google-collections",
"version": "${pom.version}"
},
{
"group": "com.google.guava",
"name": "listenablefuture",
"version": "1.0"
}
]
}
Expand Down
40 changes: 27 additions & 13 deletions integration-tests/gradle/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,30 @@ val guavaVersionJre =
val expectedReducedRuntimeClasspathAndroidVersion =
setOf(
"guava-${guavaVersionJre.replace("jre", "android")}.jar",
"failureaccess-1.0.2.jar",
"jsr305-3.0.2.jar",
"checker-qual-3.41.0.jar",
"error_prone_annotations-2.23.0.jar",
"listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar"
"failureaccess-1.0.2.jar"
)
val expectedReducedRuntimeClasspathJreVersion =
setOf(
"guava-$guavaVersionJre.jar",
"failureaccess-1.0.2.jar",
"failureaccess-1.0.2.jar"
)
val compileOnlyDependencies =
setOf(
"j2objc-annotations-2.8.jar",
"jsr305-3.0.2.jar",
"checker-qual-3.41.0.jar",
"error_prone_annotations-2.23.0.jar",
"listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar"
"error_prone_annotations-2.23.0.jar"
)
val expectedCompileClasspathAndroidVersion =
expectedReducedRuntimeClasspathAndroidVersion + setOf("j2objc-annotations-2.8.jar")
expectedReducedRuntimeClasspathAndroidVersion + compileOnlyDependencies
val expectedCompileClasspathJreVersion =
expectedReducedRuntimeClasspathJreVersion + setOf("j2objc-annotations-2.8.jar")
expectedReducedRuntimeClasspathJreVersion + compileOnlyDependencies

val extraLegacyDependencies = setOf("google-collections-1.0.jar")
val extraLegacyDependencies =
setOf(
"google-collections-1.0.jar",
"listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar"
)

buildscript {
val agpVersion = if (gradle.gradleVersion.startsWith("5.")) "3.6.4" else "7.0.4"
Expand Down Expand Up @@ -58,7 +61,7 @@ subprojects {
// - variant decision is made based on version suffix (android/jre) and not on the actual
// environment
// - runtime classpath equals the compile classpath
// - dependency conflict with Google Collections is not detected
// - dependency conflict with Google Collections is not detected and '9999.0' hack is present
if (name.startsWith("android")) {
expectedCompileClasspathAndroidVersion + extraLegacyDependencies
} else {
Expand All @@ -68,7 +71,7 @@ subprojects {
// with Gradle Module Metadata
// - variant is chosen based on the actual environment, independent of version suffix
// - reduced runtime classpath is used (w/o annotation libraries)
// - capability conflicts are detected with Google Collections
// - capability conflicts are detected between Google Collections and listenablefuture
if (name.contains("Android") && !name.contains("JreConstraint")) {
when {
name.contains("RuntimeClasspath") -> {
Expand Down Expand Up @@ -125,6 +128,17 @@ subprojects {
}
?.apply { select(this) }
}
withCapability("com.google.guava:listenablefuture") {
candidates
.find {
val idField =
it.javaClass.getDeclaredMethod(
"getId"
) // reflective access to make this compile with Gradle 5
(idField.invoke(it) as ModuleComponentIdentifier).module == "guava"
}
?.apply { select(this) }
}
}
}

Expand Down