Skip to content

Commit

Permalink
Bazel: Fix compilation in Java 9
Browse files Browse the repository at this point in the history
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
  • Loading branch information
davido authored and ejona86 committed Apr 26, 2018
1 parent 44c79fb commit 23fcedf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions java_grpc_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
12 changes: 12 additions & 0 deletions repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions stub/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)

0 comments on commit 23fcedf

Please sign in to comment.