Add support for toolchain java 15
Closes https://github.com/bazelbuild/bazel/issues/11871
I modelled this on @davido's addition of a java 14 toolchain, here:[https://github.com/bazelbuild/bazel/pull/11514](url).
The test plan has the same form:
Create java_tools from this commit:
` $ bazel build src:java_tools_java11.zip`
Switch to using the java_tools from the above step in WORKSPACE file:
```
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "remote_java_tools_linux",
urls = [
"file:///<path to the java_tools_java11.zip>",
],
)
```
Add Zulu OpenJDK15 to use as javabase in WORKSPACE file:
```
http_archive(
name = "openjdk15_linux_archive",
build_file_content = """
java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])
exports_files(["WORKSPACE"], visibility = ["//visibility:public"])
""",
strip_prefix = "zulu15.27.17-ca-jdk15.0.0-linux_x64",
urls = ["https://cdn.azul.com/zulu/bin/zulu15.27.17-ca-jdk15.0.0-linux_x64.tar.gz"],
)
```
Activate custom java toolchain and javabase in .bazelrc file:
```
build --java_toolchain=@remote_java_tools_linux//:toolchain_jdk_15
build --host_java_toolchain=@remote_java_tools_linux//:toolchain_jdk_15
build --javabase=@openjdk15_linux_archive//:runtime
build --host_javabase=@openjdk15_linux_archive//:runtime
```
Create Java 15 example class file:
```
public class Javac15Example {
static String textBlock = """
Hello,
World
""";
public static void main(String[] args) {
System.out.println(textBlock);
}
}
```
Add Bazel file to build Java 15 syntax class:
```
java_binary(
name = "Javac15Example",
srcs = ["Javac15Example.java"],
main_class = "Javac15Example",
)
```
Test that it works as expected:
```
$ bazel run java:Javac15Example
INFO: Analyzed target //java:Javac15Example (1 packages loaded, 2 targets configured).
INFO: Found 1 target...
INFO: From Building java/Javac15Example.jar (1 source file):
Target //java:Javac15Example up-to-date:
bazel-bin/java/Javac15Example.jar
bazel-bin/java/Javac15Example
INFO: Elapsed time: 1.502s, Critical Path: 1.30s
INFO: 1 process: 1 worker.
INFO: Build completed successfully, 2 total actions
INFO: Build completed successfully, 2 total actions
Hello,
World
```
Closes #12168.
PiperOrigin-RevId: 335931179
diff --git a/src/BUILD b/src/BUILD
index a7794cd..dae383d 100644
--- a/src/BUILD
+++ b/src/BUILD
@@ -753,6 +753,9 @@
"@openjdk14_darwin_archive//:WORKSPACE",
"@openjdk14_linux_archive//:WORKSPACE",
"@openjdk14_windows_archive//:WORKSPACE",
+ "@openjdk15_darwin_archive//:WORKSPACE",
+ "@openjdk15_linux_archive//:WORKSPACE",
+ "@openjdk15_windows_archive//:WORKSPACE",
"@openjdk_linux_aarch64_minimal//file",
"@openjdk_linux_minimal//file",
"@openjdk_macos_minimal//file",
@@ -773,6 +776,9 @@
"@remotejdk14_linux_for_testing//:WORKSPACE",
"@remotejdk14_macos_for_testing//:WORKSPACE",
"@remotejdk14_win_for_testing//:WORKSPACE",
+ "@remotejdk15_linux_for_testing//:WORKSPACE",
+ "@remotejdk15_macos_for_testing//:WORKSPACE",
+ "@remotejdk15_win_for_testing//:WORKSPACE",
"@rules_cc//:WORKSPACE",
"@rules_java//:WORKSPACE",
"@rules_pkg//:WORKSPACE",