Browse Source

Bazel: Support building with Java 9

Bazel@HEAD supports Java 9.

The current code has one single issue with Java 9 compliance: the usage
of javax.xml.bind.DatatypeConverter class for printHexBinary() method.
This class is not available on Java 9. One alternative is to use guava
library. Something similar was done here: [1]. But unlike the case with
checkstyle library, JGit currently doesn't use guava. Instead, we add
java.xml.bind module with --add-modules compiler option.

To build (or test) with Java 9, build custom bazel version and issue:

  $ bazel --host_javabase=/usr/lib64/jvm/java-9-openjdk build \
    --javacopt='--release 9' \
    --java_toolchain=@bazel_tools//tools/jdk:toolchain_jdk9 :all

The Java 9 support is backwards compatible.

* [1] https://github.com/checkstyle/checkstyle/issues/5027

Change-Id: I2c5203fc4e65885ce7b210f824fda85ba6d6c51d
Signed-off-by: David Ostrovsky <david@ostrovsky.org>
stable-4.11
David Ostrovsky 7 years ago committed by Matthias Sohn
parent
commit
ab1b97234d
  1. 7
      BUILD
  2. 4
      org.eclipse.jgit/BUILD

7
BUILD

@ -1,5 +1,12 @@
package(default_visibility = ["//visibility:public"]) package(default_visibility = ["//visibility:public"])
config_setting(
name = "jdk9",
values = {
"java_toolchain": "@bazel_tools//tools/jdk:toolchain_jdk9",
},
)
genrule( genrule(
name = "all", name = "all",
testonly = 1, testonly = 1,

4
org.eclipse.jgit/BUILD

@ -14,6 +14,10 @@ RESOURCES = glob(["resources/**"])
java_library( java_library(
name = "jgit", name = "jgit",
srcs = SRCS, srcs = SRCS,
javacopts = select({
"//:jdk9": ["--add-modules=java.xml.bind"],
"//conditions:default": [],
}),
resource_strip_prefix = "org.eclipse.jgit/resources", resource_strip_prefix = "org.eclipse.jgit/resources",
resources = RESOURCES, resources = RESOURCES,
deps = [ deps = [

Loading…
Cancel
Save