我想将ant构建迁移到 Bazel 4.2.1。ant 构建使用 Eclipse 编译器 (ecj-3.27.0)。
在 Bazel 中声明 Java 编译器的方式是java_toolchain
.
所以我看了一下输出bazel query @bazel_tools//tools/jdk:all
并尝试使用 vanilla 工具链作为灵感(bazelisk query --output=build @bazel_tools//tools/jdk:toolchain_vanilla
)。
java_toolchain(
# modified settings
name = "my-ecj-toolchain",
javabuilder = ["@ecj//:ecj.jar"], # my Eclipse compiler jar
target_version = "8",
# prevent ecj.jar's error message 'unknown option --persistent_workers'
javac_supports_workers = False,
# prevent ecj.jar's error message 'unknown option --persistent_workers'
javac_supports_multiplex_workers = False,
# keeping most vanilla-toolchain settings
bootclasspath = ["@bazel_tools//tools/jdk:platformclasspath"],
misc = ["-XDskipDuplicateBridges=true", "-XDcompilePolicy=simple", "-g", "-parameters"],
jvm_opts = [],
tools = ["@bazel_tools//tools/jdk:javac_jar", "@bazel_tools//tools/jdk:java_compiler_jar", "@bazel_tools//tools/jdk:jdk_compiler_jar"],
singlejar = ["@bazel_tools//tools/jdk:singlejar"],
forcibly_disable_header_compilation = True,
genclass = ["@bazel_tools//tools/jdk:genclass"],
ijar = ["@bazel_tools//tools/jdk:ijar"],
header_compiler = ["@bazel_tools//tools/jdk:turbine_direct"],
header_compiler_direct = ["@bazel_tools//tools/jdk:turbine_direct"],
jacocorunner = "@bazel_tools//tools/jdk:JacocoCoverageFilegroup",
)
但是,它仍然不起作用。ecj.jar
编译输出未知选项--output
。
bazel aquery MYTARGET
显示整个编译器命令行(以及更多构建步骤):
Command Line: (exec external/remotejdk11_linux/bin/java \
-jar \
external/ecj/ecj.jar \
--output \
bazel-out/k8-opt/bin/[...].jar \
--native_header_output \
bazel-out/k8-opt/bin/[...]-native-header.jar \
--output_manifest_proto \
bazel-out/k8-opt/bin/[...].jar_manifest_proto \
--compress_jar \
--output_deps_proto \
bazel-out/k8-opt/bin/[...].jdeps \
--bootclasspath \
bazel-out/k8-opt/bin/external/bazel_tools/tools/jdk/platformclasspath.jar \
--sources \
bazel-out/k8-opt/bin/[...].java \
--javacopts \
-target \
8 \
'-XDskipDuplicateBridges=true' \
'-XDcompilePolicy=simple' \
-g \
-parameters \
-g \
-- \
--target_label \
bazel-out/k8-opt/bin/[...]:[...] \
--strict_java_deps \
ERROR \
--direct_dependencies \
[...]
我不知道任何接受--output
. 我必须以ecj.jar
不同的方式通过吗?