-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Add Gradle capability declarations to detect duplicate Guava artifacts #7990
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
base: master
Are you sure you want to change the base?
Conversation
This update introduces several new Guava-related dependencies in the module.json file, including guava-base, guava-jdk5, sisu-guava, and others. These additions enhance the project's support for Guava libraries. RELNOTES=n/a
Thanks. I took the liberty of pulling some more items from #6666 in #7991. (Because of the specifics of how our process works, we always submit an internal CL, which generates a new GitHub PR, but it still gets attributed to the original contributor.) If you don't want your name to show up on the additions there, let me know, and I can add them in a separate change. |
Huh, somehow this breaks the Gradle integration test:
Any theories? |
Sorry, I forgot to say: That's https://github.com/google/guava/blob/master/util/gradle_integration_tests.sh. You might need to set JAVA_HOME to JDK11 or at least some version close to that. |
@cpovirk Thanks for pointing me to the Gradle integration test
What I found: The servicemix capability declaration creates an internal conflict within Guava's module metadata. Since all variants (jreApiElements, androidApiElements, etc.) declare they provide the same capability, Gradle rejects the entire module before it can apply variant selection rules. I noticed the build config has special capability resolution logic for withCapability("com.google.collections:google-collections") {
candidates
.find {
val idField = it.javaClass.getDeclaredMethod("getId")
(idField.invoke(it) as ModuleComponentIdentifier).module == "guava"
}
?.apply { select(this) }
} Rather than adding similar logic for servicemix, I've removed its capability declaration while keeping the other 4 capabilities. The specific failing test now passes:
This seems like a reasonable compromise - we still get duplicate detection for the other artifacts while avoiding the variant conflict issue. |
Thanks! Hmm, I wonder what's special about that one? Really, I wonder if that's the one that's behaving as expected: Maybe Gradle should be forcing us to resolve the conflict for all the libraries? Maybe, to make that happen, we need to list the various conflicting libraries as dependencies in the integration tests and probably as But wait, maybe we're seeing the conflict even in the PR's current form?
I wonder if the single conflict created by pulling in |
fixes #6666
Problem
Users can accidentally include duplicate Guava artifacts (guava-jdk5, guava-base, sisu-guava, etc.) alongside the main Guava library, causing classpath conflicts and runtime issues that are difficult to debug.
Solution
Declare that Guava provides the capabilities of known duplicate artifacts in module.json, following the existing google-collections pattern. This enables Gradle to detect and report conflicts at build time.
Changes
Note: The servicemix capability was removed after testing revealed it caused conflicts between Gradle variants.
Testing
Breaking Changes
Builds that currently (incorrectly) include both Guava and duplicate artifacts will now fail with a capability conflict error. Users must resolve by excluding the duplicate artifact or using Gradle's capability resolution.
Why this breaking change is necessary: