Bazel: Add support for toolchain_java11

This change also removes the support for building with Java 9
and 10.

Test Plan:

* Run the tests with Java 8 toolchain (the same as before this change):

  $ bazel test //...

* Run the tests with remote Java 11 toolchain (new feature added here):

  $ bazel test --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 \
    //...

Change-Id: Ib67dcc50a43f998bc8f5a363a8f681e3693d1f26
This commit is contained in:
David Ostrovsky
2019-06-22 14:21:38 +02:00
parent 3021ced2e6
commit cf4f70bc2a
6 changed files with 23 additions and 22 deletions

4
BUILD
View File

@@ -4,9 +4,9 @@ load("//tools/bzl:pkg_war.bzl", "pkg_war")
package(default_visibility = ["//visibility:public"]) package(default_visibility = ["//visibility:public"])
config_setting( config_setting(
name = "java9", name = "java11",
values = { values = {
"java_toolchain": "@bazel_tools//tools/jdk:toolchain_java9", "java_toolchain": "@bazel_tools//tools/jdk:toolchain_java11",
}, },
) )

View File

@@ -31,17 +31,17 @@ To check the installed version of Java, open a terminal window and run:
`java -version` `java -version`
[[java-10]] [[java-12]]
==== Java 10 support ==== Java 12 support
Java 10 (and newer) is supported through vanilla java toolchain Java 12 (and newer) is supported through vanilla java toolchain
link:https://docs.bazel.build/versions/master/toolchains.html[Bazel option]. link:https://docs.bazel.build/versions/master/toolchains.html[Bazel option].
To build Gerrit with Java 10 and newer, specify vanilla java toolchain and To build Gerrit with Java 12 and newer, specify vanilla java toolchain and
provide the path to JDK home: provide the path to JDK home:
``` ```
$ bazel build \ $ bazel build \
--define=ABSOLUTE_JAVABASE=<path-to-java-10> \ --define=ABSOLUTE_JAVABASE=<path-to-java-12> \
--host_javabase=@bazel_tools//tools/jdk:absolute_javabase \ --host_javabase=@bazel_tools//tools/jdk:absolute_javabase \
--host_java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla \ --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla \
--java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla \ --java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla \
@@ -53,7 +53,7 @@ bazel test runs the test using the target javabase:
``` ```
$ bazel test \ $ bazel test \
--define=ABSOLUTE_JAVABASE=<path-to-java-10> \ --define=ABSOLUTE_JAVABASE=<path-to-java-12> \
--javabase=@bazel_tools//tools/jdk:absolute_javabase \ --javabase=@bazel_tools//tools/jdk:absolute_javabase \
--host_javabase=@bazel_tools//tools/jdk:absolute_javabase \ --host_javabase=@bazel_tools//tools/jdk:absolute_javabase \
--host_java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla \ --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla \
@@ -66,7 +66,7 @@ they could be added to ~/.bazelrc resource file:
``` ```
$ cat << EOF > ~/.bazelrc $ cat << EOF > ~/.bazelrc
> build --define=ABSOLUTE_JAVABASE=<path-to-java-10> > build --define=ABSOLUTE_JAVABASE=<path-to-java-12>
> build --javabase=@bazel_tools//tools/jdk:absolute_javabase > build --javabase=@bazel_tools//tools/jdk:absolute_javabase
> build --host_javabase=@bazel_tools//tools/jdk:absolute_javabase > build --host_javabase=@bazel_tools//tools/jdk:absolute_javabase
> build --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla > build --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla
@@ -78,30 +78,31 @@ Now, invoking Bazel with just `bazel build :release` would include
all those options. all those options.
Note that the follow option must be added to `container.javaOptions` Note that the follow option must be added to `container.javaOptions`
in `$gerrit_site/etc/gerrit.config` to run Gerrit with Java 10|11|...: in `$gerrit_site/etc/gerrit.config` to run Gerrit with Java 12:
``` ```
[container] [container]
javaOptions = --add-opens=jdk.management/com.sun.management.internal=ALL-UNNAMED javaOptions = --add-opens=jdk.management/com.sun.management.internal=ALL-UNNAMED
``` ```
[[java-9]] [[java-11]]
==== Java 9 support ==== Java 11 support
Java 9 is supported through alternative java toolchain Java 11 is supported through alternative java toolchain
link:https://docs.bazel.build/versions/master/toolchains.html[Bazel option]. link:https://docs.bazel.build/versions/master/toolchains.html[Bazel option].
The Java 9 support is backwards compatible. Java 8 is still the default. To build Gerrit with Java 11, specify JDK 11 java toolchain:
To build Gerrit with Java 9, specify JDK 9 java toolchain:
``` ```
$ bazel build \ $ bazel build \
--host_java_toolchain=@bazel_tools//tools/jdk:toolchain_java9 \ --host_javabase=@bazel_tools//tools/jdk:remote_jdk11 \
--java_toolchain=@bazel_tools//tools/jdk:toolchain_java9 \ --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 :release
``` ```
Note that the follow option must be added to `container.javaOptions` Note that the follow option must be added to `container.javaOptions`
in `$gerrit_site/etc/gerrit.config` to run Gerrit with Java 9: in `$gerrit_site/etc/gerrit.config` to run Gerrit with Java 11:
``` ```
[container] [container]

View File

@@ -17,7 +17,7 @@ java_library(
data = ["//lib:LICENSE-Apache2.0"], data = ["//lib:LICENSE-Apache2.0"],
exports = ["@greenmail//jar"], exports = ["@greenmail//jar"],
runtime_deps = select({ runtime_deps = select({
"//:java9": POST_JDK8_DEPS, "//:java11": POST_JDK8_DEPS,
"//:java_next": POST_JDK8_DEPS, "//:java_next": POST_JDK8_DEPS,
"//conditions:default": [], "//conditions:default": [],
}), }),

View File

@@ -7,7 +7,7 @@ DUMMY = ["dummy.sh"]
sh_test( sh_test(
name = "test_examples", name = "test_examples",
srcs = select({ srcs = select({
"//:java9": DUMMY, "//:java11": DUMMY,
"//:java_next": DUMMY, "//:java_next": DUMMY,
"//conditions:default": ["run.sh"], "//conditions:default": ["run.sh"],
}), }),

View File

@@ -80,7 +80,7 @@ _java_doc = rule(
def java_doc(**kwargs): def java_doc(**kwargs):
libs = kwargs.get("libs", []) libs = kwargs.get("libs", [])
libs = libs + select({ libs = libs + select({
"//:java9": [], "//:java11": [],
"//:java_next": [], "//:java_next": [],
# TODO(davido): Remove this dependency, when Java 8 support is removed. # TODO(davido): Remove this dependency, when Java 8 support is removed.
# auto-value generates @javax.annotation.Generated annotation on generated # auto-value generates @javax.annotation.Generated annotation on generated

View File

@@ -82,7 +82,7 @@ def junit_tests(name, srcs, **kwargs):
) )
jvm_flags = kwargs.get("jvm_flags", []) jvm_flags = kwargs.get("jvm_flags", [])
jvm_flags = jvm_flags + select({ jvm_flags = jvm_flags + select({
"//:java9": POST_JDK8_OPTS, "//:java11": POST_JDK8_OPTS,
"//:java_next": POST_JDK8_OPTS, "//:java_next": POST_JDK8_OPTS,
"//conditions:default": [], "//conditions:default": [],
}) })