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
This commit is contained in:
parent
60ea6d91f5
commit
0bceb04b26
2
BUILD
2
BUILD
@ -15,7 +15,7 @@ config_setting(
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "java10",
|
||||
name = "java_next",
|
||||
values = {
|
||||
"java_toolchain": ":toolchain_vanilla",
|
||||
},
|
||||
|
@ -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]
|
||||
@ -14,11 +14,11 @@ To build Gerrit from source, you need:
|
||||
* zip, unzip
|
||||
* gcc
|
||||
|
||||
[[Java 10 support]]
|
||||
Java 10 is supported through vanilla java toolchain
|
||||
[[Java 10 and newer version support]]
|
||||
Java 10 (and newer 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 \
|
||||
@ -29,12 +29,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
|
||||
```
|
||||
|
||||
@ -51,13 +79,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]]
|
||||
|
@ -1129,6 +1129,12 @@ maven_jar(
|
||||
sha1 = "65bd0cacc9c79a21c6ed8e9f588577cd3c2f85b9",
|
||||
)
|
||||
|
||||
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.
|
||||
|
@ -1,8 +1,23 @@
|
||||
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 = 1,
|
||||
data = ["//lib:LICENSE-Apache2.0"],
|
||||
visibility = ["//visibility:public"],
|
||||
exports = ["@greenmail//jar"],
|
||||
runtime_deps = select({
|
||||
"//:java9": POST_JDK8_DEPS,
|
||||
"//:java_next": POST_JDK8_DEPS,
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
)
|
||||
|
@ -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",
|
||||
]
|
||||
|
||||
@ -82,7 +81,7 @@ def junit_tests(name, srcs, **kwargs):
|
||||
jvm_flags = kwargs.get("jvm_flags", [])
|
||||
jvm_flags = jvm_flags + select({
|
||||
"//:java9": POST_JDK8_OPTS,
|
||||
"//:java10": POST_JDK8_OPTS,
|
||||
"//:java_next": POST_JDK8_OPTS,
|
||||
"//conditions:default": [],
|
||||
})
|
||||
native.java_test(
|
||||
|
Loading…
Reference in New Issue
Block a user