如何让 Gradle 选择正确的番石榴变体?

问题描述 投票:0回答:1

我正在尝试在我的 Java 项目中使用 OpenRewrite 插件,它需要 guava。 Gradle 无法在两个变体之间进行选择,因为该插件不检查属性 org.gradle.jvm.environment。这两个变体是 androidRuntimeElements 和 jreRuntimeElements。

如何从我的项目中排除 android 运行时变体或让 Gradle 选择 jre 运行时变体?

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'

我尝试用谷歌搜索这个问题,但没有找到任何答案。我还尝试从 build.gradle 配置块中排除番石榴,但我无法仅排除 android 运行时变体。

java gradle build.gradle guava openrewrite
1个回答
0
投票

虽然我看不到你的 OpenRewrite 配置,但我可以看到 rewrite-python 至少已经过时了。那里有一个新的 1.0.8 版本,以及许多其他 OpenRewrite 插件和模块,专门用于解决最近的一些 Guava 版本问题。请务必使用最新版本,通常可以通过以下链接在 GitHub 上查看:

© www.soinside.com 2019 - 2024. All rights reserved.