Guava Version
33.5.0
Description
In a gradle project I have a build that uses some Java tooling as part of its
build machinery, but is not, itself, a Java project. One of the tooling
dependencies (javaparser) has a dependency on Guava.
For historical reasons that project's build.gradle.kts applied the
java-library plugin. When I removed it because its default tasks were causing
problems with other tasks and, as noted, no Java artifacts were being produced,
the build failed with an error:
Variant Selection Exception:
org.gradle.internal.component.resolution.failure.exception.VariantSelectionByAttributesException
caused by Resolution Failure:
org.gradle.internal.component.resolution.failure.type.NoCompatibleVariantsFailure
Gradle can no longer resolve a Guava variant that it can use. Note that javaparser is explicitly depending on the -jre Guava version. (https://github.com/javaparser/javaparser/blob/11a99ae61df28b19fb9b64e5f7c216fa71dc4020/pom.xml#L432-L437)
There's a minimal repro here: https://github.com/Saxonica/guava-variant-problem
This project contains two Gradle sub-projects, java_lib and
non_java whose build.gradle.kts differ only in the plugin they apply.
non_java applies the base plugin, and java_lib applies the java-library
plugin. They both contain a simple configuration which declares a dependency on
Guava.
Running ./gradlew java_lib:dependencies shows that Guava resolves fine, and
./gradlew non_java:depdendencies shows the failure.
This is defintely unexpected behvaiour, and seems like buggy behaviour, though I
am really not sure if this is a Gradle problem or a Guava Gradle metadata
problem.
I imagine this is related to #7059, #6801 and friends
Example
Clone https://github.com/Saxonica/guava-variant-problem and run the following:
./gradlew non_java:dependencies`
Expected Behavior
A properly resolved dependency tree, whose macguffin configuration's dependency tree should be identical to the result of running ./gradlew java_lib:dependencies:
> Task :non_java:dependencies
------------------------------------------------------------
Project ':non_java'
------------------------------------------------------------
macguffin
\--- com.google.guava:guava:33.6.0-jre
+--- com.google.guava:failureaccess:1.0.3
+--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
+--- org.jspecify:jspecify:1.0.0
+--- com.google.errorprone:error_prone_annotations:2.47.0
\--- com.google.j2objc:j2objc-annotations:3.1
macguffinRuntime (n)
\--- com.google.guava:guava:33.6.0-jre (n)
(n) - A dependency or dependency configuration that cannot be resolved.
A web-based, searchable dependency report is available by adding the --scan option.
BUILD SUCCESSFUL in 414ms
Actual Behavior
> Task :non_java:dependencies
------------------------------------------------------------
Project ':non_java'
------------------------------------------------------------
macguffin
\--- com.google.guava:guava:33.6.0-jre FAILED
macguffinRuntime (n)
\--- com.google.guava:guava:33.6.0-jre (n)
(n) - A dependency or dependency configuration that cannot be resolved.
A web-based, searchable dependency report is available by adding the --scan option.
BUILD SUCCESSFUL in 414ms
Packages
No response
Platforms
No response
Checklist
Guava Version
33.5.0
Description
In a gradle project I have a build that uses some Java tooling as part of its
build machinery, but is not, itself, a Java project. One of the tooling
dependencies (javaparser) has a dependency on Guava.
For historical reasons that project's
build.gradle.ktsapplied thejava-libraryplugin. When I removed it because its default tasks were causingproblems with other tasks and, as noted, no Java artifacts were being produced,
the build failed with an error:
Gradle can no longer resolve a Guava variant that it can use. Note that
javaparseris explicitly depending on the-jreGuava version. (https://github.com/javaparser/javaparser/blob/11a99ae61df28b19fb9b64e5f7c216fa71dc4020/pom.xml#L432-L437)There's a minimal repro here: https://github.com/Saxonica/guava-variant-problem
This project contains two Gradle sub-projects,
java_libandnon_javawhosebuild.gradle.ktsdiffer only in the plugin they apply.non_javaapplies thebaseplugin, andjava_libapplies thejava-libraryplugin. They both contain a simple configuration which declares a dependency on
Guava.
Running
./gradlew java_lib:dependenciesshows that Guava resolves fine, and./gradlew non_java:depdendenciesshows the failure.This is defintely unexpected behvaiour, and seems like buggy behaviour, though I
am really not sure if this is a Gradle problem or a Guava Gradle metadata
problem.
I imagine this is related to #7059, #6801 and friends
Example
Expected Behavior
A properly resolved dependency tree, whose
macguffinconfiguration's dependency tree should be identical to the result of running./gradlew java_lib:dependencies:Actual Behavior
Packages
No response
Platforms
No response
Checklist
I agree to follow the code of conduct.
I can reproduce the bug with the latest version of Guava available.