As of today (2018-9-25), JDK 11 is generally available: http://jdk.java.net/11/.
Bazel should support it, including:
--host_javabase) [#7219]--javabase) [done]--java_toolchain/--host_java_toolchain)@cushon Do you have a road map / timeline for support for JDK 11?
@cushon please add a priority label, thanks!
cc @iirina
FYI, I have to disable some tests for ubuntu1804_java11
# Some prebuilt jars doesn't run with Java 11
- "-//src/test/shell/bazel:external_integration_test"
- "-//src/test/shell/bazel:maven_test"
# Re-enable once bootstrap works with Java 11
- "-//src/test/shell/bazel:bazel_bootstrap_distfile_test
https://buildkite.com/bazel/google-bazel-presubmit/builds/14214#d7b484bc-ed66-4bf0-aa53-6b148c255e03
@cushon should JDK 11 host runtime support (--host_javabase) be updated? The linked issue is closed
This can be closed altogether.
you mean everything is supported? are there docs for bazel and jdk11?
for example what is the toolchain I should use for jdk11
https://github.com/bazelbuild/bazel/blob/108bc5aaf46c4ec5e6dc0ac7c81c2f16d9ae2a21/tools/jdk/BUILD shows remote_jdk10 and remote_jdk11, but no toolchain_java10 or toolchain_java11 from what I can tell.
I don't think you're supposed to use the toolchains named in that style anyway if you want the new stuff, the one that's just called toolchain or remote_toolchain now points to the recent work: https://github.com/bazelbuild/bazel/commit/bad5a2beb9f8441d97b88d5c4323055e710f72e8#diff-b53d77ce419e665f48b6c7bca4965357
But I haven't checked whether the language level for Java 11 is usable yet, and buildjar still seems to depend on langtools' javac which is javac-9+181-r4173-1.jar unless I'm misinterpreting something (based on my understanding of https://github.com/bazelbuild/bazel/issues/5723#issuecomment-463240615).
support for the Java 11 language level (--java_toolchain/--host_java_toolchain)
Can someone clarify how the point 3 from the issue description is solved on Bazel@HEAD?
The Java 11 language level works for me at head:
$ cat BUILD Hello.java
java_binary(
name = "Hello",
srcs = ["Hello.java"],
main_class = "Hello",
)
class Hello {
public static void main(String[] args) {
var message = "Hello world";
System.err.println(message);
}
}
$ JAVA_HOME=<path to JDK 11> bazel run --javacopt='--release 11' :Hello
Hello world
Thanks, is this the recommended way of setting the language level, or will the toolchain rule be updated to have a release_version argument?
Also assuming this works with remote_jdk11 as the host_javabase and not just when setting JAVA_HOME?
@cushon, can you clarify how to use this feature? Bazel at head defines toolchain_java8 and toolchain_java9, but not toolchain_java10 or toolchain_java11. I was able to roll my own like this:
default_java_toolchain(
name = "toolchain_java11",
source_version = "11",
target_version = "11",
visibility = [
"//visibility:public",
],
)
then activate it by default from my bazelrc:
build --java_toolchain=//:toolchain_java11
build --host_java_toolchain=//:toolchain_java11
But now building a simple java_library fails with the following:
java.lang.IllegalArgumentException: invalid source release: 11
at jdk.compiler/com.sun.tools.javac.main.Arguments.error(Arguments.java:913)
at jdk.compiler/com.sun.tools.javac.main.Arguments.doProcessArgs(Arguments.java:383)
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 com.google.devtools.build.buildjar.javac.BlazeJavacMain.compile(BlazeJavacMain.java:99)
at com.google.devtools.build.buildjar.ReducedClasspathJavaLibraryBuilder.compileSources(ReducedClasspathJavaLibraryBuilder.java:57)
at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.compileJavaLibrary(SimpleJavaLibraryBuilder.java:116)
at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.run(SimpleJavaLibraryBuilder.java:123)
at com.google.devtools.build.buildjar.BazelJavaBuilder.processRequest(BazelJavaBuilder.java:106)
at com.google.devtools.build.buildjar.BazelJavaBuilder.runPersistentWorker(BazelJavaBuilder.java:68)
at com.google.devtools.build.buildjar.BazelJavaBuilder.main(BazelJavaBuilder.java:46)
I believe this means the JVM used in the host configuration doesn't understand source release 11. OK, let's set this explicitly in bazelrc:
build --javabase @bazel_tools//tools/jdk:remote_jdk11
build --host_javabase @bazel_tools//tools/jdk:remote_jdk11
But this doesn't make a difference; I get the same stack trace as above. Is there a piece of the puzzle I'm missing?
With bazel@HEAD @bazel_tools//tools/jdk:toolchain is a toolchain for java 11, but still targets JDK 8.
I tried reproducing with your example but I could run a Java 11 binary. Make sure that you are using bazel built@HEAD otherwise the default_java_toolchain still points to a Java 10 toolchain.
We are planning to soon make available the toolchains for java version 9-12 under https://github.com/bazelbuild/java_tools.
1d82cf8b51171f2e1c01c582529d8f558940f41b introduced @bazel_tools//tools/jdk:toolchain_java10 and @bazel_tools//tools/jdk:toolchain_java11. You can try them out with bazel@HEAD.
Most helpful comment
Thanks, is this the recommended way of setting the language level, or will the toolchain rule be updated to have a
release_versionargument?Also assuming this works with remote_jdk11 as the host_javabase and not just when setting JAVA_HOME?