Open LiYing2010 opened 1 year ago
I reproduced this issue with a very simple build script:
build.gradle.kts
:
plugins {
java
}
repositories {
mavenCentral()
maven { setUrl("https://repo.maven.apache.org/maven2") }
}
dependencies {
implementation("com.google.guava:guava:31.1-jre")
implementation("com.google.collections:google-collections:1.0")
}
and tested for some versions:
32.0.0-jre
---> works fine
32.0.1-jre
---> works fine
31.1-jre
---> works fine
32.1.0-jre
---> failed with same error
32.1.1-jre
---> failed with same error
32.1.2-jre
---> failed with same error
32.1.3-jre
---> failed with same error
error message is:
Could not resolve: com.google.guava:guava:32.1.0-jre
Could not resolve: com.google.collections:google-collections:1.0
Could not resolve: com.google.guava:guava:32.1.0-jre
Could not resolve: com.google.collections:google-collections:1.0
oh
I found this in your release note:
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 added the following to my test build script:
configurations.all {
resolutionStrategy.capabilitiesResolution.withCapability("com.google.collections:google-collections") {
select("com.google.guava:guava:0")
}
}
and it fixed the dependencies conflict in that test build script
but I am confused, is this a workaround? or the official solution?
also, this does NOT work for our real project,
because google-collections
is not a dependency of our project, but a transitive dependency of checkstyle
plugin
I don't know how to tell gradle to select guava
over google-collections
in plugin dependency
oh~~~ good news
this workaround works for our real project: 😅
dependencies {
modules {
// replace old dependency `google-collections` with `guava`
module("com.google.collections:google-collections") {
replacedBy("com.google.guava:guava", "google-collections is part of guava")
}
}
}
looks like it also applied to the transitive dependency of checkstyle
plugin
now our project works just fine ~~~
Description
We are using
checkstyle
plugin in a gradle (v8.3
) projectcheckstyle
is the latest version10.12.4
, and our project also usecom.google.guava:guava:31.1-jre
and everything works finebut when I upgrade
guava
to32.1.2-jre
, it makecheckstyle
failed with following error:some investigation:
I checked the dependency list of
checkstyle
: https://checkstyle.sourceforge.io/dependencies.html looks like it depends oncom.google.guava:guava:32.0.1-jre
and there is a transitive dependencycom.google.collections:google-collections:1.0
toowhich means,
guava:32.0.1-jre
+google-collections:1.0
+checkstyle 10.12.4
should workso I changed my dependency to
guava:32.0.1-jre
, and it worked!I tested some versions of
guava
:32.1.0-jre
---> failed with same error32.1.1-jre
---> failed with same error32.1.2-jre
---> failed with same error32.1.3-jre
---> failed with same error32.0.0-jre
---> works fine32.0.1-jre
---> works fine31.1-jre
---> works finelooks like this error only occurs in
32.1.x
versionand I check the maven repo: https://repo1.maven.org/maven2/com/google/guava/guava/ the only strange thing I found is: all the
32.1.x
version has a fileguava-32.1.x-jre.module
, with following content:I am not sure, but I guess this is why gradle cannot resolve
com.google.collections:google-collections:1.0
?Example