Comments (2)
This is the expected behavior. Although, I know that it is confusing, because the version string with the -jre
in it looks like it is the variant selection, but it is not (see explanation further down).
To select the JRE version in Android do what you have commented out:
dependencies.constraints {
testImplementation("com.google.guava:guava") {
attributes {
attribute(
TargetJvmEnvironment.TARGET_JVM_ENVIRONMENT_ATTRIBUTE,
objects.named(TargetJvmEnvironment.STANDARD_JVM)
)
}
}
}
It's not a "workaround", but a way to tell Gradle to select a different variant than your JVM environment's default.
Since 32.1.1
, The -jre
in the version number no longer has a meaning for Gradle.
That is, 33.0.0-jre
and 33.0.0-android
are the same from for Gradle. This way, there are no longer accidental switches from jre
to android
(or the other way around) by version conflict resolution. In previous versions, you could declare ...-jre
but get ...-android
, because of a higher ...-android
version somewhere in the dependency graph.
Ideally, there won't be two versions 33.0.0-jre
and 33.0.0-android
but just 33.0.0
. But I guess that schema needs to be kept for Maven consumers. I fully understand why encoding the "variant" in the version was chosen back in the day. But strictly speaking it is "wrong". The version conflict resolution of tools (both Gradle and Maven) is not made for using the version
like this and that leads to follow up confusion.
Because of the above, it gets confusing when you look at the resolution result of Gradle. In your example it says that it resolved to -> 33.0.0-jre
. But as the -jre
here has no meaning, it could have been 33.0.0-android
as well and the result would be the same. What matters is the variant it resolves to and the Jar file that's behind that variant. Unfortunately, the dependencies
tasks does not show that. It would be nice if the dependencies
task would have some kind of "extended mode" that also shows the variants and files.
You can use dependencyInsight
to get the full picture (almost, as this also does not show the Jar file):
$ gradle dependencyInsight --configuration releaseUnitTestRuntimeClasspath --dependency com.google.guava:guava
> Task :dependencyInsight
com.google.guava:guava:33.0.0-jre
Variant androidRuntimeElements:
| Attribute Name | Provided | Requested |
|-------------------------------------------------|--------------|--------------|
| org.gradle.dependency.bundling | external | |
| org.gradle.jvm.version | 8 | |
| org.gradle.libraryelements | jar | |
| org.gradle.status | release | |
| org.gradle.category | library | library |
| org.gradle.jvm.environment | android | android |
| org.gradle.usage | java-runtime | java-runtime |
| com.android.build.api.attributes.AgpVersionAttr | | 8.2.1 |
| com.android.build.api.attributes.BuildTypeAttr | | release |
Selection reasons:
- By constraint
- By conflict resolution: between versions 33.0.0-jre and 31.1-jre
Here we have the clues Variant androidRuntimeElements
and org.gradle.jvm.environment = android
With this comment, I only want to explain the situation. I don't want to say that things are perfect as they are. But I am not sure what a concrete next action would be. Things I see:
- On the Guava side, it would be good to get rid of the
-jre
and-android
in the version at some point, but I am not sure if and how that could ever be possible. - On the Gradle side, I think there is room for improving what the dependency task reports.
- ...and in the DSL for defining attribute values (
attributes { attribute(TargetJvmEnvironment.TARGET_JVM_ENVIRONMENT_ATTRIBUTE, objects.named(TargetJvmEnvironment.STANDARD_JVM)) }
is very clumsy and the variant selection mechanisms are still quite hard to understand if a build user needs to interact with them directly (as it is the case here).
from guava.
Sorry, @TWiStErRob, for the trouble with this, and thanks again, @jjohannes, for jumping in with an explanation.
I still need to do more about this class of problem. My recent work has been mostly to add APIs like Sets.toImmutableSet
to the Android flavor so that it differs from the JRE flavor mostly just in implementation details, rather than in public API. So far, I've added APIs as package-private, and I'm waiting to see if users encounter problems when they adopt 33.0.0. If no one reports problems, then I expect to make the APIs public
and add more such APIs, at which point things might work for you even when Gradle selects the Android variant. (Thanks for being among those to test 33.0.0, and sorry again.)
I think you're right that this is fundamentally the same as #6801, so I'll try to consolidate things back there.
from guava.
Related Issues (20)
- Support for weak values in `Multimap`
- debug android HOT 1
- Addition of Built-In Methods for Primitive Math operations HOT 1
- Could not find error_prone_annotations-2.11.0.jar HOT 1
- Gradle 6.x isn't able to pick right Guava variant HOT 3
- Guava build fails on `master` with JDK 21 HOT 4
- Add action version comments in GitHub workflow files HOT 1
- Supply Chain Security
- Is `com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava` really necessary? HOT 2
- SmoothRateLimiter.SmoothBursty obtaining too many permits without failure HOT 1
- Certain versions of Guava on Maven central no longer working on Java 11 HOT 2
- guava-gwt should publish Gradle module metadata or somehow fix POM HOT 2
- java.lang.NoSuchMethodError: 'void com.google.common.base.Preconditions.checkState(boolean, java.lang.String, long) HOT 1
- `Suppliers.memoize()` thread pinning HOT 6
- Copying a filtered collection with ImmutableSet.copyOf() should require visiting each element only once HOT 1
- com.google.common.collect.Range#hasLowerBound determination error after deserialization HOT 7
- InternetDomainName.topPrivateDomain() throws exception for Amazonaws-Domain HOT 4
- Use Gradle module available-at tag instead of files for redirecting jre vs android consumers HOT 5
- Failing while building guava version v31.0.1 using mvn clean install HOT 3
- Make `Striped.custom` public HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from guava.