强制Bazel仅使用本地Java

时间:2019-04-28 08:38:58

标签: bazel

我想在封闭的环境中使用bazel,而该环境没有不受控制的Internet访问。我想强制bazel使用本地安装的Java,而不是下载一个。我无法弄清楚所需的标志组合-这是我尝试的方法:

$ java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)
$ javac -version
javac 1.8.0_171
$ bazel clean --expunge
$ bazel info release
release 0.24.1
$ bazel build //hello 
# This builds a 'hello world' cpp file.
# This rule also downloads some rules, would be nice to avoid it as
INFO: Build completed successfully, 6 total actions well
$ bazel test --nofetch //hello:hello_test
ERROR: /home/erenon/.cache/bazel/_bazel_erenon/afacf41c7e3fc3f4ea7510d344b4de38/external/bazel_tools/tools/jdk/BUILD:218:1: no such package '@remote_java_tools//': to fix, run
        bazel fetch //...
External repository @remote_java_tools not found and fetching repositories is disabled. and referenced by '@bazel_tools//tools/jdk:JacocoCoverageRunner'
ERROR: Analysis of target '//hello:hello_test' failed; build aborted: no such package '@remote_java_tools//': to fix, run
        bazel fetch //...
External repository @remote_java_tools not found and fetching repositories is disabled.
INFO: Elapsed time: 0.160s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (3 packages loaded, 27 targets configured)
FAILED: Build did NOT complete successfully (3 packages loaded, 27 targets configured)

我通过更复杂的命令行获得了相同的结果:

$ bazel test --nofetch --define=ABSOLUTE_JAVABASE=/usr/lib/jvm/java-8-openjdk-amd64 --host_javabase=@local_jdk//:jdk --javabase=@local_jdk//:jdk --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8 --java_toolchain=@bazel_tools//tools/jdk:toolchain_hostjdk8 //hello:hello_test
INFO: Build options --define, --host_java_toolchain, --host_javabase, and 2 more have changed, discarding analysis cache.
ERROR: /home/erenon/.cache/bazel/_bazel_erenon/afacf41c7e3fc3f4ea7510d344b4de38/external/bazel_tools/tools/jdk/BUILD:218:1: no such package '@remote_java_tools//': to fix, run
        bazel fetch //...
External repository @remote_java_tools not found and fetching repositories is disabled. and referenced by '@bazel_tools//tools/jdk:JacocoCoverageRunner'
ERROR: Analysis of target '//hello:hello_test' failed; build aborted: no such package '@remote_java_tools//': to fix, run
        bazel fetch //...
External repository @remote_java_tools not found and fetching repositories is disabled.
INFO: Elapsed time: 0.215s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 50 targets configured)
FAILED: Build did NOT complete successfully (0 packages loaded, 50 targets configured)

我尝试了 java 标志的所有组合,没有运气。我还尝试启用每个不兼容的更改(--all_incompatible_changes),这会产生不同的结果:

INFO: Build options --incompatible_allow_python_version_transitions, --incompatible_auto_configure_host_platform, --incompatible_cc_coverage, and 24 more have changed, discarding analysis cache.
ERROR: While resolving toolchains for target //hello:hello_test: com.google.devtools.build.lib.packages.BuildFileNotFoundException: no such package '@local_config_platform//': to fix, run
        bazel fetch //...
External repository @local_config_platform not found and fetching repositories is disabled.
ERROR: Analysis of target '//hello:hello_test' failed; build aborted: com.google.devtools.build.lib.packages.BuildFileNotFoundException: no such package '@local_config_platform//': to fix, run
        bazel fetch //...
External repository @local_config_platform not found and fetching repositories is disabled.
INFO: Elapsed time: 0.228s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded, 0 targets configured)
FAILED: Build did NOT complete successfully (1 packages loaded, 0 targets configured)

它现在寻找@local_config_platform

  • 是否存在可以从源代码构建并包含这些依赖项的目标目标?
  • 是否存在启用bazel test --nofetch的其他命令行?

1 个答案:

答案 0 :(得分:1)

看来从源头启动挡板可以解决此问题。从GitHub下载bazel-<version>-dist.zip后,在解压缩的文件夹中:

env EXTRA_BAZEL_ARGS="--host_javabase=@local_jdk//:jdk" bash ./compile.sh

已编译的输出放置在输出/面板中。这是一个自包含的Bazel二进制文件,没有嵌入式JDK。

https://docs.bazel.build/versions/master/install-compile-source.html