From 85b488f7fa12cfe7bfd3c10aecd25aefda734a17 Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Wed, 31 Jan 2018 09:01:27 +0100 Subject: Bazel: Support building with Java 9 Fixes: #4256. Bazel@HEAD supports Java 9. The current code has one single issue with Java 9 compliance: the usage of sun.misc package. We add jdk.unsupported module with --add-modules compiler option for now. Long term, the usage of non public API should be avoided. To build 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 \ :protobuf_java --- BUILD | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'BUILD') diff --git a/BUILD b/BUILD index 2902e9e2..b786ff64 100644 --- a/BUILD +++ b/BUILD @@ -4,6 +4,17 @@ licenses(["notice"]) exports_files(["LICENSE"]) +################################################################################ +# Java 9 configuration +################################################################################ + +config_setting( + name = "jdk9", + values = { + "java_toolchain": "@bazel_tools//tools/jdk:toolchain_jdk9", + }, +) + ################################################################################ # Protobuf Runtime Library ################################################################################ @@ -608,7 +619,10 @@ java_library( ]) + [ ":gen_well_known_protos_java", ], - javacopts = ["-source 7", "-target 7"], + javacopts = select({ + "//:jdk9": ["--add-modules=jdk.unsupported"], + "//conditions:default": ["-source 7", "-target 7"], + }), visibility = ["//visibility:public"], ) -- cgit v1.2.3