0

我目前正在bazel 4.2.1尝试建立一种习惯的某些java_library规则java_toolchain,而另一种习惯则很少。

据我了解,原因之一jvm_opts就是["--module-path", "$(location @ecj//:ecj.jar)"]只能在java_toolchain级别上设置。此外,我们希望能够java_toochains在单个构建运行中为不同的项目目录在同一个工作区中使用多个。

有没有办法在同一个工作区和同一个构建运行中指定一个 java_library 的 java_toolchain1 和一个不同的 java_library 的 java_toolchain2 ?

包含工具链的 BUILD.bazel 文件

load("@rules_java//java:defs.bzl", "java_toolchain")

java_toolchain(
  name = "toolchain_custom",
  source_version = "8",
  target_version = "8",
  bootclasspath = ["@bazel_tools//tools/jdk:platformclasspath"],
  misc = ["-XDskipDuplicateBridges=true", "-XDcompilePolicy=simple", "-g", "-parameters"],
  javac_supports_workers = True,
  tools = ["@bazel_tools//tools/jdk:javac_jar", "@bazel_tools//tools/jdk:java_compiler_jar", "@bazel_tools//tools/jdk:jdk_compiler_jar"],
  javabuilder = ["@bazel_tools//tools/jdk:vanillajavabuilder"],
  singlejar = ["@bazel_tools//tools/jdk:singlejar"],
  ...
)

java_toolchain(
  name = "jdt_ecj_toolchain",
  bootclasspath = ["@bazel_tools//tools/jdk:platformclasspath"],
  misc = ["-XDskipDuplicateBridges=true", "-XDcompilePolicy=simple", "-g", "-parameters", "-XSFmax_stdouterr_bytes=6000000"],
  jvm_opts = ["--module-path", "$(location @ecj//:ecj.jar)"],
  javac_supports_workers = True,
  tools = ["@ecj//:ecj.jar"],
  javabuilder = ["@jdt_java_toolchain//builder/export:JdtJavaToolchainRef"],
  singlejar = ["@bazel_tools//tools/jdk:singlejar"],
  ....
)

包含 java_rules 的 BUILD.bazel 文件

# use toolchain_custom to build ProjectRunnerCustom
java_library(
    name = "ProjectRunnerCustom",
    srcs = glob(["Project1/src/main/java/com/example/*.java"]),
)

# use jdt_ecj_toolchain to build ProjectRunnerEcJ
java_library(
    name = "ProjectRunnerEcJ",
    srcs = glob(["Project2/src/main/java/com/example/*.java"]),
)
4

0 回答 0