google-truth - 导致项目其余部分降级到 guava android 的真相扩展
问题描述
如果我将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.
这是否意味着除了 maven dep on 之外的任何东西com.google.guava:guava:28.2-jre
?如果没有,下一个最简单的解决方法是什么?
解决方案
这里的关键词是“最新”:您需要依赖(在撰写本文时)30.1-jre。我编辑了文档以强调这一点。
(您可以在各个位置看到最新版本,包括:Maven Central、Maven Central Search、Guava GitHub 页面。)
问题是:
- 一些工具(包括 Gradle 以及
maven_install
来自 Bazel's 的规则rules_jvm_external
)在您的传递依赖项中找到的所有版本中选择任何给定工件的“最新”版本。 - Truth 1.1取决于版本 30.0-android。
- 30.0-android 被认为比 28.2-jre“更新”(因为 30 大于 28)。
- -android 版本缺少 Java 8 API。
(因此,您实际上可以通过依赖30.0-jre 以上的任何-jre 版本来解决此问题:由于字母顺序,30.0-jre 被认为比 30.0-android“更新”。有趣!)
不幸的是,Maven 生态系统不支持为每个版本(JRE+Android)提供两种“风格”的好方法。(人们经常建议使用 Maven“分类器”,但这并不能真正解决问题。)
为未来:
- Gradle:Gradle正在与我们合作提供自己的解决方案,但还没有完全准备好。
- Maven:Maven 不太可能提供帮助。(它甚至不会尝试选择“最新”版本,更不用说支持“口味”了。)
- Bazel:我不知道
rules_jvm_external
(使用Coursier的)是否有计划支持“口味”。(编辑一下:在理想的世界中,我宁愿自己指定我的所有 repo 的传递依赖项及其版本,而不是让构建系统尝试为我解决它。这有助于避免像这样的意外。但这会带来它自己的挑战,我们只是在我们自己的基于 Bazel 的项目中为解决这些问题做出了渐进的努力。)
推荐阅读
- spring - 何时使用 @ImportAutoConfiguration 与 @Import
- python - 类图(面向对象编程)
- r - 尝试将值分配给 R 中的矩阵时出错
- c# - 动态加载程序集的兼容性
- sql - SQL 查询 - 匹配 5 中至少 4 个值的条件
- c++ - boost::variant - 对变体应用算术的最简单方法
- python - 用于将 Excel 插入 postgresql 数据库的 Django Bulk_create
- c - 等到用户输入值并将其分配给 var
- python - “charmap”编解码器无法解码位置 33222 中的字节 0x8d:字符映射到
- python - 如何在 url_for 语句中添加 /?