commit | 9450552707a82dd47745d32b98a94afe34c5a58c | [log] [tgz] |
---|---|---|
author | Jonathan Perry <jonpez63@gmail.com> | Wed Oct 07 12:45:34 2020 -0700 |
committer | Copybara-Service <copybara-worker@google.com> | Wed Oct 07 12:46:25 2020 -0700 |
tree | 783a2ffb858f4f9ba15800383ff26c6a674144cd | |
parent | 4a8cbf5216341333d77a02cd500448a245334d0e [diff] |
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
{Fast, Correct} - Choose two
Build and test software of any size, quickly and reliably.
Speed up your builds and tests: Bazel rebuilds only what is necessary. With advanced local and distributed caching, optimized dependency analysis and parallel execution, you get fast and incremental builds.
One tool, multiple languages: Build and test Java, C++, Android, iOS, Go, and a wide variety of other language platforms. Bazel runs on Windows, macOS, and Linux.
Scalable: Bazel helps you scale your organization, codebase, and continuous integration solution. It handles codebases of any size, in multiple repositories or a huge monorepo.
Extensible to your needs: Easily add support for new languages and platforms with Bazel's familiar extension language. Share and re-use language rules written by the growing Bazel community.
Follow our tutorials:
See CONTRIBUTING.md