diff options
author | David Ostrovsky <david@ostrovsky.org> | 2018-08-25 07:37:54 +0200 |
---|---|---|
committer | David Pursehouse <dpursehouse@collab.net> | 2019-07-05 01:48:28 +0000 |
commit | 987abc7c83799fcce5e018003a676b66dc216c90 (patch) | |
tree | 9c82cbaeba14f9c16cfffe6a07503dfe768c949e | |
parent | c163ad7bd0a97368c04055449c1ab6da78575b82 (diff) |
Bazel: Add support for Java 11 and newer Java versions
VanillaJavaBuilder is used to build with Java 10. It turns out, that the
same approach can be used to support build with newer Java versions.
Rename Bazel config setting from java10 to java_next to reflect that
generic approach, so that we can still use java_next even for Java 12
and later versions.
In Java 11 javax.activation module was removed from the JDK. To rectify,
add this test dependency to greenmail library explicitly, but do it
conditionally, depending on what JDK is used.
Similarly, in Java 11 javax.xml.bind module was removed from the JDK.
JGit's WalkEncryption class transitively depends on it. It seems that
gerrit doesn't use this class, so that we can ignore that for now.
Alternatively, we would have to ship javax.xml.bind:jaxb-api with
Gerrit release.war.
Test Plan:
* To build, run:
$ bazel build --host_javabase=:absolute_javabase \
--define=ABSOLUTE_JAVABASE=/usr/lib64/jvm/java-11 \
--define=USE_ABSOLUTE_JAVABASE=true \
--host_java_toolchain=//:toolchain_vanilla \
--java_toolchain=//:toolchain_vanilla \
:release
* To run the tests, --javabase option must be passed as well, because
bazel test runs the test using the target javabase:
$ bazel build --host_javabase=:absolute_javabase \
--javabase=:absolute_javabase \
[...]
//...
Change-Id: I4a4b4124048e5f45d7deb75d520ccc3f76443ade
(cherry picked from commit 0bceb04b26e2c9e054c6f5aa7373d32864a21d1c)
-rw-r--r-- | BUILD | 2 | ||||
-rw-r--r-- | Documentation/dev-bazel.txt | 45 | ||||
-rw-r--r-- | WORKSPACE | 6 | ||||
-rw-r--r-- | lib/greenmail/BUILD | 14 | ||||
-rw-r--r-- | tools/bzl/junit.bzl | 3 |
5 files changed, 58 insertions, 12 deletions
@@ -13,7 +13,7 @@ config_setting( ) config_setting( - name = "java10", + name = "java_next", values = { "java_toolchain": ":toolchain_vanilla", }, diff --git a/Documentation/dev-bazel.txt b/Documentation/dev-bazel.txt index 85517f994d..6d86f433b9 100644 --- a/Documentation/dev-bazel.txt +++ b/Documentation/dev-bazel.txt @@ -6,7 +6,7 @@ To build Gerrit from source, you need: * A Linux or macOS system (Windows is not supported at this time) -* A JDK for Java 8|9|10 +* A JDK for Java 8|9|10|11|... * Python 2 or 3 * Node.js * link:https://www.bazel.io/versions/master/docs/install.html[Bazel] @@ -22,8 +22,8 @@ To build Gerrit from source, you need: Java 10 is supported through vanilla java toolchain link:https://docs.bazel.build/versions/master/toolchains.html[Bazel option]. -To build Gerrit with Java 10, specify vanilla java toolchain and provide -path to Java 10 home: +To build Gerrit with Java 10 and newer, specify vanilla java toolchain and +provide the path to JDK home: ``` $ bazel build --host_javabase=:absolute_javabase \ @@ -34,12 +34,40 @@ path to Java 10 home: :release ``` -Note that the following options must be added to `container.javaOptions` -in `$gerrit_site/etc/gerrit.config` to run Gerrit with Java 10: +To run the tests, `--javabase` option must be passed as well, because +bazel test runs the test using the target javabase: + +``` + $ bazel test --host_javabase=:absolute_javabase \ + --javabase=:absolute_javabase \ + --define=ABSOLUTE_JAVABASE=<path-to-java-10> \ + --define=USE_ABSOLUTE_JAVABASE=true \ + --host_java_toolchain=//:toolchain_vanilla \ + --java_toolchain=//:toolchain_vanilla \ + //... +``` + +To avoid passing all those options on every Bazel build invocation, +they could be added to ~/.bazelrc resource file: + +``` +$ cat << EOF > ~/.bazelrc +> build --define=ABSOLUTE_JAVABASE=<path-to-java-10> +> build --javabase=:absolute_javabase +> build --host_javabase=:absolute_javabase +> build --host_java_toolchain=//:toolchain_vanilla +> build --java_toolchain=//:toolchain_vanilla +> EOF +``` + +Now, invoking Bazel with just `bazel build :release` would include +all those options. + +Note that the follow option must be added to `container.javaOptions` +in `$gerrit_site/etc/gerrit.config` to run Gerrit with Java 10|11|...: ``` [container] - javaOptions = --add-modules java.activation javaOptions = --add-opens=jdk.management/com.sun.management.internal=ALL-UNNAMED ``` @@ -58,13 +86,12 @@ To build Gerrit with Java 9, specify JDK 9 java toolchain: :release ``` -Note that the following 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: ``` [container] - javaOptions = --add-modules java.activation \ - --add-opens=jdk.management/com.sun.management.internal=ALL-UNNAMED + javaOptions = --add-opens=jdk.management/com.sun.management.internal=ALL-UNNAMED ``` [[build]] @@ -1158,6 +1158,12 @@ maven_jar( sha1 = "ed8b772eb077a9cb50e44e90899c66a9a6c00e67", ) +maven_jar( + name = "javax-activation", + artifact = "javax.activation:activation:1.1.1", + sha1 = "485de3a253e23f645037828c07f1d7f1af40763a", +) + load("//tools/bzl:js.bzl", "bower_archive", "npm_binary") # NPM binaries bundled along with their dependencies. diff --git a/lib/greenmail/BUILD b/lib/greenmail/BUILD index 062f866303..587fd8a8ea 100644 --- a/lib/greenmail/BUILD +++ b/lib/greenmail/BUILD @@ -1,8 +1,22 @@ package(default_visibility = ["//visibility:public"]) +POST_JDK8_DEPS = [":javax-activation"] + +java_library( + name = "javax-activation", + testonly = 1, + data = ["//lib:LICENSE-DO_NOT_DISTRIBUTE"], + exports = ["@javax-activation//jar"], +) + java_library( name = "greenmail", testonly = True, data = ["//lib:LICENSE-Apache2.0"], exports = ["@greenmail//jar"], + runtime_deps = select({ + "//:java9": POST_JDK8_DEPS, + "//:java_next": POST_JDK8_DEPS, + "//conditions:default": [], + }), ) diff --git a/tools/bzl/junit.bzl b/tools/bzl/junit.bzl index 2c7a33254b..68923659ad 100644 --- a/tools/bzl/junit.bzl +++ b/tools/bzl/junit.bzl @@ -68,7 +68,6 @@ POST_JDK8_OPTS = [ # Enforce JDK 8 compatibility on Java 9, see # https://docs.oracle.com/javase/9/intl/internationalization-enhancements-jdk-9.htm#JSINT-GUID-AF5AECA7-07C1-4E7D-BC10-BC7E73DC6C7F "-Djava.locale.providers=COMPAT,CLDR,SPI", - "--add-modules java.activation", "--add-opens=jdk.management/com.sun.management.internal=ALL-UNNAMED", ] @@ -81,7 +80,7 @@ def junit_tests(name, srcs, **kwargs): ) jvm_flags = kwargs.get("jvm_flags", []) jvm_flags = jvm_flags + select({ - "//:java10": POST_JDK8_OPTS, + "//:java_next": POST_JDK8_OPTS, "//:java9": POST_JDK8_OPTS, "//conditions:default": [], }) |