1

I'm trying to use the OpenRewrite plugin in my Java project and it requires guava. Gradle is unable to choose between two variants because the plugin doesn't check attribute org.gradle.jvm.environment. The two variants are androidRuntimeElements and jreRuntimeElements.

How can I either exclude the android runtime variant from my project or make Gradle pick the jre runtime variant?

Execution failed for task ':rewriteResolveDependencies'.
> Could not resolve all files for configuration ':detachedConfiguration1'.
   > Could not resolve com.google.guava:guava:31.1-jre.
     Required by:
         project : > org.openrewrite:rewrite-python:1.0.7
      > The consumer was configured to find attribute 'org.gradle.category' with value 'library', attribute 'org.gradle.usage' with value 'java-runtime', attribute 'org.gradle.libraryelements' with value 'jar', attribute 'org.gradle.dependency.bundling' with value 'external'. However we cannot choose between the following variants of com.google.guava:guava:32.1.1-jre:
          - androidRuntimeElements
          - jreRuntimeElements
        All of them match the consumer attributes:
          - Variant 'androidRuntimeElements' capabilities com.google.collections:google-collections:32.1.1-jre and com.google.guava:guava:32.1.1-jre and com.google.guava:listenablefuture:1.0 declares attribute 'org.gradle.category' with value 'library', attribute 'org.gradle.dependency.bundling' with value 'external', attribute 'org.gradle.libraryelements' with value 'jar', attribute 'org.gradle.usage' with value 'java-runtime':
              - Unmatched attributes:
                  - 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.status 'release' but the consumer didn't ask for it
          - Variant 'jreRuntimeElements' capabilities com.google.collections:google-collections:32.1.1-jre and com.google.guava:guava:32.1.1-jre and com.google.guava:listenablefuture:1.0 declares attribute 'org.gradle.category' with value 'library', attribute 'org.gradle.dependency.bundling' with value 'external', attribute 'org.gradle.libraryelements' with value 'jar', attribute 'org.gradle.usage' with value 'java-runtime':
              - Unmatched attributes:
                  - 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.status 'release' but the consumer didn't ask for it
        The following variants were also considered but didn't match the requested attributes:
          - Variant 'androidApiElements' capabilities com.google.collections:google-collections:32.1.1-jre and com.google.guava:guava:32.1.1-jre and com.google.guava:listenablefuture:1.0 declares attribute 'org.gradle.category' with value 'library', attribute 'org.gradle.dependency.bundling' with value 'external', attribute 'org.gradle.libraryelements' with value 'jar':
              - Incompatible because this component declares attribute 'org.gradle.usage' with value 'java-api' and the consumer needed attribute 'org.gradle.usage' with value 'java-runtime'
          - Variant 'jreApiElements' capabilities com.google.collections:google-collections:32.1.1-jre and com.google.guava:guava:32.1.1-jre and com.google.guava:listenablefuture:1.0 declares attribute 'org.gradle.category' with value 'library', attribute 'org.gradle.dependency.bundling' with value 'external', attribute 'org.gradle.libraryelements' with value 'jar':
              - Incompatible because this component declares attribute 'org.gradle.usage' with value 'java-api' and the consumer needed attribute 'org.gradle.usage' with value 'java-runtime'

I tried Googling the issue, but didn't find any answers. I also tried excluding guava from my build.gradle configuration block, but I'm unable to exclude only the android runtime variant.

  • Is anything in https://github.com/google/guava/issues/6612#issuecomment-1662362097 or the following posts of help? That would mean adding "org.gradle.usage=java-runtime" and/or "org.gradle.jvm.environment=standard-jvm"... or the "TARGET_JVM_ENVIRONMENT_ATTRIBUTE" suggestion... or "id 'jvm-ecosystem'".... – Chris Povirk Aug 28 '23 at 13:38

1 Answers1

0

While I can't see your OpenRewrite config, I can see that rewrite-python at least is out of date. There's a new 1.0.8 release there, as well as for a number of other OpenRewrite plugins and modules, specifically to resolve some recent Guava version issues. Be sure to use the latest versions, typically visible on GitHub through links such as:

Tim
  • 19,793
  • 8
  • 70
  • 95
  • Thanks for your comment! Unfortunately this does not solve my issue, as it is still a problem in the latest version of OpenRewrite. – Martin Johansen Aug 14 '23 at 09:51
  • Sorry to hear! You mentioned the plugin should check the jvm environment attribute. I'm not too familiar there, but could you log an issue against the rerite-gradle-plugin repository with more details? – Tim Aug 15 '23 at 14:57