简体   繁体   English

如何解决bazel中的java_toolchain

[英]How to resolve the java_toolchain in bazel

Bazel discusses how to create java toolchains, eg Bazel讨论了如何创建java工具链,例如

java_toolchain(
  name = "my_toolchain",
  encoding = "UTF-8",
  source_version = "8",
  target_version = "8",
  misc = [
    "-extra_checks:on",
  ],
)

from a blog post on configuring java builds . 来自关于配置java版本的博客文章 But, how can resolve the java toolchain from a rule? 但是,如何从规则中解析java工具链?

java_toolchain = ctx.toolchains["@bazel_tools//<something here>"]

I expect something like the above, but I could not find documentation on the bazel java rules documentation page . 我希望像上面这样的东西,但我找不到关于bazel java rules文档页面的文档

You are right, this would be the preferred way to access the Java toolchain. 你是对的,这将是访问Java工具链的首选方式。 Unfortunately, the Java rules do not currently support toolchain resolution, so this isn't possible, and the Java toolchain will need to be accessed via a private attribute that depends on @bazel_tools//tools/jdk:current_java_toolchain. 遗憾的是,Java规则目前不支持工具链解析,因此这是不可能的,并且需要通过依赖于@ bazel_tools // tools / jdk:current_java_toolchain的私有属性来访问Java工具链。 See the default_javacopts rule for an example. 有关示例,请参阅default_javacopts规则。

There is work starting soon to address this, and we'll be sure to announce to the community when Java rules support toolchain resolution and this works the way you expect. 很快就会开始着手解决这个问题,当Java规则支持工具链解析时,我们肯定会向社区宣布,这会按照您的预期方式运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM