Expose vanilla java toolchain
To use the latest supported language level from the --host_javabase, use
VanillaJavaBuilder (which should work with most host JDKs) and leave the
source/target/bootclasspath unset so they default to the latest
supported versions.
With this in place, new java_runtime can be used, e.g.:
java_runtime(
name = "jdk11",
java_home = "/usr/lib64/jvm/java-11",
visibility = ["//visibility:public"],
)
Now the JDK11 can be used with the language level 11:
$ bazel build --host_javabase=:jdk11 \
--host_java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla \
--java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla \
:a
Related: #5723
Closes #5984.
PiperOrigin-RevId: 213859466
diff --git a/tools/jdk/BUILD b/tools/jdk/BUILD
index f4974f0..41b21b5 100644
--- a/tools/jdk/BUILD
+++ b/tools/jdk/BUILD
@@ -236,6 +236,27 @@
actual = "toolchain_java8",
)
+# The 'vanilla' toolchain is an unsupported alternative to the default.
+#
+# It does not provider any of the following features:
+# * Error Prone
+# * Strict Java Deps
+# * Header Compilation
+# * Reduced Classpath Optimization
+#
+# It uses the version of javac from the `--host_javabase` instead of the
+# embedded javac, which may not be source- or bug-compatible with the embedded
+# javac.
+#
+# However it does allow using a wider range of `--host_javabase`s, including
+# versions newer than the current embedded JDK.
+default_java_toolchain(
+ name = "toolchain_vanilla",
+ forcibly_disable_header_compilation = True,
+ javabuilder = [":vanillajavabuilder"],
+ jvm_opts = [],
+)
+
[
default_java_toolchain(
name = "toolchain_java%d" % release,