Bazel: Fix compilation in Java 9

Fixes: #3633.

Test Plan:

On most recent Bazel version run:

  $ bazel --host_javabase=/usr/lib64/jvm/java-9-openjdk \
    build --javacopt='--release 9' \
    --java_toolchain=@bazel_tools//tools/jdk:toolchain_jdk9 \
    examples:helloworld_java_grpc
This commit is contained in:
David Ostrovsky 2018-04-26 23:37:57 +02:00 committed by Eric Anderson
parent 44c79fbe5d
commit 23fcedfb6f
3 changed files with 24 additions and 0 deletions

View File

@ -109,6 +109,7 @@ def java_grpc_library(name, srcs, deps, flavor=None,
added_deps = [
"@io_grpc_grpc_java//core",
"@io_grpc_grpc_java//stub",
"@io_grpc_grpc_java//stub:javax_annotation",
"@com_google_guava_guava//jar",
]
if flavor == "normal":

View File

@ -27,6 +27,7 @@ def grpc_java_repositories(
omit_io_netty_tcnative_boringssl_static=False,
omit_io_opencensus_api=False,
omit_io_opencensus_grpc_metrics=False,
omit_javax_annotation=False,
omit_junit_junit=False,
omit_org_apache_commons_lang3=False):
"""Imports dependencies for grpc-java."""
@ -82,6 +83,8 @@ def grpc_java_repositories(
io_opencensus_api()
if not omit_io_opencensus_grpc_metrics:
io_opencensus_grpc_metrics()
if not omit_javax_annotation:
javax_annotation()
if not omit_junit_junit:
junit_junit()
if not omit_org_apache_commons_lang3:
@ -277,6 +280,15 @@ def io_opencensus_grpc_metrics():
sha1 = "d57b877f1a28a613452d45e35c7faae5af585258",
)
def javax_annotation():
# TODO(davido): maven_jar does not support neverlink attribute.
# To circumvent use http_file following by java_import.
native.http_file(
name = "javax_annotation_api",
sha256 = "5909b396ca3a2be10d0eea32c74ef78d816e1b4ead21de1d78de1f890d033e04",
urls = ["http://central.maven.org/maven2/javax/annotation/javax.annotation-api/1.2/javax.annotation-api-1.2.jar"],
)
def junit_junit():
native.maven_jar(
name = "junit_junit",

View File

@ -12,3 +12,14 @@ java_library(
"@com_google_guava_guava//jar",
],
)
# javax.annotation.Generated is not included in the default root modules in 9,
# see: http://openjdk.java.net/jeps/320.
java_import(
name = "javax_annotation",
jars = [
"@javax_annotation_api//file",
],
neverlink = 1, # @Generated is source-retention
visibility = ["//visibility:public"],
)