【问题标题】:Truth extensions causing rest of project to downgrade to guava android导致项目其余部分降级到 guava android 的真相扩展
【发布时间】:2021-01-09 18:17:45
【问题描述】:

如果我将 com.google.truth.extensions:truth-proto-extension:1.1 jar 添加到我的 bazel 工作区,它似乎完全从 com.google.guava:guava:28.2-jre 中删除类,导致类似的错误

import static com.google.common.collect.ImmutableMap.toImmutableMap;
^
  symbol:   static toImmutableMap
  location: class ImmutableMap
java/com/google/fhir/protogen/ProtoGenerator.java:316: error: cannot find symbol
            .collect(toImmutableMap(def -> def.getId().getValue(), def -> def));
                     ^
  symbol:   method toImmutableMap((def)->def[...]lue(),(def)->def)
  location: class ProtoGenerator

你的文档说

One warning: Truth depends on the “Android” version of Guava, a subset of the “JRE” version.
If your project uses the JRE version, be aware that your build system might select the Android version instead.
If so, you may see “missing symbol” errors.
The easiest fix is usually to add a direct dependency on the newest JRE version of Guava.

这是否意味着除了 com.google.guava:guava:28.2-jre 上的 maven dep 之外的其他任何东西?如果没有,下一个最简单的解决方法是什么?

【问题讨论】:

    标签: google-truth


    【解决方案1】:

    这里的关键词是“最新”:您需要依赖(在撰写本文时)30.1-jre。我有edited the docs to emphasize this

    (您可以在各个位置看到最新版本,包括:Maven CentralMaven Central Searchthe Guava GitHub page。)

    问题是:

    • 一些工具(包括 Gradle 以及来自 Bazel 的 rules_jvm_externalmaven_install 规则)在您的传递依赖项中找到的所有版本中选择任何给定工件的“最新”版本。
    • 真相 1.1 depends on version 30.0-android.
    • 30.0-android 被认为比 28.2-jre“更新”(因为 30 大于 28)。
    • -android 版本缺少 Java 8 API。

    (因此,您实际上可以通过 any -jre 30.0-jre 以上的版本来解决此问题:由于字母顺序,30.0-jre 被认为比 30.0-android“更新”。有趣!)

    不幸的是,Maven 生态系统不支持为每个版本(JRE+Android)提供两种“风格”的好方法。 (人们经常建议使用 Maven“分类器”,但 does not actually solve the problem。)

    为了未来:

    • Gradle:Gradle 是 working with us to provide its own solution,但还没有完全准备好。
    • Maven:Maven 不太可能提供帮助。 (它甚至不会尝试选择“最新”版本,更不用说支持“口味”了。)
    • Bazel:我不知道rules_jvm_external(使用Coursier)是否有计划支持“口味”。 (编辑一下:在理想的世界中,我宁愿自己指定我的所有 repo 的传递依赖项及其版本,而不是让构建系统尝试为我解决它。这有助于避免像这样的意外。但这会带来它自己的挑战,我们只在incremental effort 上解决了我们自己的基于 Bazel 的项目。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-04
      • 2018-06-16
      • 2020-10-11
      • 2011-09-15
      • 2021-10-15
      • 1970-01-01
      • 2020-11-15
      • 1970-01-01
      相关资源
      最近更新 更多