google / guava

Google core libraries for Java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Gradle 6.x isn't able to pick right Guava variant

GeertZijlmans1 opened this issue · comments

Description

I have a Java application which is build using Gradle 6.8.3 and uses Microsoft's Graph SDK v6.3.0. The Graph SDK has a transitive dependency on (and requires) guava 33.0.0-jre.

Gradle 6.8.3 is a hard requirement and we cannot upgrade to a newer version of Gradle soon.

Example

* Install Gradle 6.x (e.g. 6.8.3) 
* Create a Java application which uses Gradle to build jar for it and add the Graph SDK v6.3.0 as a dependency.

Note that I also tried with the suggestions made about setting attributes (e.g. setting org.gradle.jvm.environment to 'standard-jvm'), but that still did not help my cause.

Maybe a good example how to configure your Gradle build file for version 6.x would be nice (as Gradle 7 and later don't have this problem according to the Internet)

Expected Behavior

Application builds without problems

Actual Behavior

Building the application with the dependency throws the following failure:

Could not resolve com.google.guava:guava:33.0.0-jre.
Required by:
project :ourapp > com.microsoft.graph:microsoft-graph:6.3.0

Also it mentions that no selection could be made to determine the right variant:

Failed to build and package the app, because:
AmbiguousConfigurationSelectionException: Cannot choose between the following variants of com.google.guava:guava:33.0.0-jre:

  • androidRuntimeElements
  • jreRuntimeElements
    All of them match the consumer attributes:
  • Variant 'androidRuntimeElements' capabilities com.google.collections:google-collections:33.0.0-jre and com.google.guava:guava:33.0.0-jre:
    • Unmatched attributes:
      • Provides org.gradle.category 'library' but the consumer didn't ask for it
      • Provides org.gradle.dependency.bundling 'external' but the consumer didn't ask for it
      • Provides org.gradle.jvm.environment 'android' but the consumer didn't ask for it
      • Provides org.gradle.jvm.version '8' but the consumer didn't ask for it
      • Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
      • Provides org.gradle.status 'release' but the consumer didn't ask for it
      • Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it
  • Variant 'jreRuntimeElements' capabilities com.google.collections:google-collections:33.0.0-jre and com.google.guava:guava:33.0.0-jre:
    • Unmatched attributes:
      • Provides org.gradle.category 'library' but the consumer didn't ask for it
      • Provides org.gradle.dependency.bundling 'external' but the consumer didn't ask for it
      • Provides org.gradle.jvm.environment 'standard-jvm' but the consumer didn't ask for it
      • Provides org.gradle.jvm.version '8' but the consumer didn't ask for it
      • Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
      • Provides org.gradle.status 'release' but the consumer didn't ask for it
      • Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it

Packages

No response

Platforms

No response

Checklist

Sorry for the trouble :( It sounds like you've already found https://github.com/google/guava/releases/tag/v32.1.0 and perhaps some other discussions. Those other discussions include #6801 (comment) and posts throughout #6612.

If you're able to share a sample project, that may improve the chances that someone could help. You may end up with better luck on Stack Overflow, since my understanding is that most such errors need to be fixed by changes to a plugin or elsewhere in the build configuration :(

This may be a bit of a naive, but a simple solution should be to disable the module metadata for the dependency (docs) because in most cases the maven pom is satisfactory.

repositories {
  mavenCentral()
  exclusiveContent {
    forRepository {
      maven {
        url 'https://repo.maven.apache.org/maven2/'
        metadataSources {
          mavenPom()
          artifact()
        }
      }
    }
    filter {
      includeModule 'com.google.guava', 'guava'
    }
  }
}

@cpovirk It seems no longer to be necessary as the Microsoft Graph SDK falsely still had a dependency on the Google Guava library. Just finished removing that dependency for the Graph SDK. So I'll expect it to be no problem for my case anymore. But I could imagine that other developers might run into a similar problem (though I think we need to upgrade our Gradle version first).