在Ubuntu上使用Java 11的Bazel

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Ubuntu上使用Java 11的Bazel相关的知识,希望对你有一定的参考价值。

我正在尝试将Java 11用于Java家庭作业。它在我的OS X机器上可以正常工作,但是我的机器上安装了JDK 13。我的讲师使用Ubuntu,并且未安装最新的Java。我如何让Bazel使用JAVA 11而不需要我的讲师更新他的JDK。

我的.bazelrc如下:

test --test_output=errors
test --cache_test_results=yes


test --java_toolchain=@bazel_tools//tools/jdk:toolchain_java11

当我跑步时:

bazel test java/test/edu/berkeley/cs/util:{hashset,hashmap}

我收到这个奇妙的错误。

Starting local Bazel server and connecting to it...
INFO: Writing tracer profile to '/home/tomgrant/.cache/bazel/_bazel_tomgrant/75fd013422b9b35862a74918dc983c19/command.profile.gz'
INFO: Analyzed 2 targets (23 packages loaded, 287 targets configured).
INFO: Found 2 test targets...
INFO: Deleting stale sandbox base /home/tomgrant/.cache/bazel/_bazel_tomgrant/75fd013422b9b35862a74918dc983c19/sandbox
ERROR: /home/tomgrant/.cache/bazel/_bazel_tomgrant/75fd013422b9b35862a74918dc983c19/external/bazel_tools/tools/jdk/BUILD:319:1: Action external/bazel_tools/tools/jdk/platformclasspath.jar failed (Exit 1) java failed: error executing command external/remotejdk11_linux/bin/java -XX:+IgnoreUnrecognizedVMOptions '--add-exports=jdk.compiler/com.sun.tools.javac.platform=ALL-UNNAMED' -cp ... (remaining 4 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
Exception in thread "main" java.lang.IllegalArgumentException: external/local_jdk
    at jdk.compiler/com.sun.tools.javac.file.Locations$SystemModulesLocationHandler.isCurrentPlatform(Locations.java:1862)
    at jdk.compiler/com.sun.tools.javac.file.Locations$SystemModulesLocationHandler.update(Locations.java:1851)
    at jdk.compiler/com.sun.tools.javac.file.Locations$SystemModulesLocationHandler.handleOption(Locations.java:1798)
    at jdk.compiler/com.sun.tools.javac.file.Locations.handleOption(Locations.java:2062)
    at jdk.compiler/com.sun.tools.javac.file.BaseFileManager.handleOption(BaseFileManager.java:269)
    at jdk.compiler/com.sun.tools.javac.file.BaseFileManager$2.handleFileManagerOption(BaseFileManager.java:222)
    at jdk.compiler/com.sun.tools.javac.main.Option.process(Option.java:1138)
    at jdk.compiler/com.sun.tools.javac.main.Option.handleOption(Option.java:1086)
    at jdk.compiler/com.sun.tools.javac.file.BaseFileManager.handleOption(BaseFileManager.java:232)
    at jdk.compiler/com.sun.tools.javac.main.Arguments.doProcessArgs(Arguments.java:390)
    at jdk.compiler/com.sun.tools.javac.main.Arguments.processArgs(Arguments.java:347)
    at jdk.compiler/com.sun.tools.javac.main.Arguments.init(Arguments.java:246)
    at jdk.compiler/com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:185)
    at DumpPlatformClassPath.dumpJDK9AndNewerBootClassPath(DumpPlatformClassPath.java:106)
    at DumpPlatformClassPath.main(DumpPlatformClassPath.java:67)
Caused by: java.nio.file.NoSuchFileException: external/local_jdk
    at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
    at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
    at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)
    at java.base/sun.nio.fs.UnixFileSystemProvider.isSameFile(UnixFileSystemProvider.java:333)
    at java.base/java.nio.file.Files.isSameFile(Files.java:1530)
    at jdk.compiler/com.sun.tools.javac.file.Locations$SystemModulesLocationHandler.isCurrentPlatform(Locations.java:1860)
    ... 14 more
INFO: Elapsed time: 8.063s, Critical Path: 0.26s
INFO: 3 processes: 3 linux-sandbox.
FAILED: Build did NOT complete successfully
//java/test/edu/berkeley/cs/util:hashset                              NO STATUS

FAILED: Build did NOT complete successfully

[如果有人能解决这个问题,将很高兴向您发送一袋Blue Bottle bean或类似的东西,价格为$ 20 = D

答案
到目前为止,我从Bazel Dev的此链接中得到了一个答案!来自gerrit.googlesource.com

并且请查看此部分:

[[java-11]]==== Java 11支持通过备用Java工具链支持Java 11链接:https://docs.bazel.build/versions/master/toolchains.html[Bazel选项]。要使用Java 11构建Gerrit,请指定JDK 11 Java工具链:

$ bazel build --host_javabase=@bazel_tools//tools/jdk:remote_jdk11 --javabase=@bazel_tools//tools/jdk:remote_jdk11 --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_java11 --java_toolchain=@bazel_tools//tools/jdk:toolchain_java11 :release

以上是关于在Ubuntu上使用Java 11的Bazel的主要内容,如果未能解决你的问题,请参考以下文章

从安装程序安装 bazel 0.21.0 在 ubuntu 18.04.1 上失败

Bazel构建工具的安装

在Ubuntu中从源码编译TensorFlow

如何获取 Bazel 执行的命令

bazel:使用 WSL 的 bash 而不是 MSYS64

如何获取Bazel执行的命令