You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Java 9: cannot find symbol javax.annotation.Generated #3633
For gRPC's build, after #3633 I don't see a problem with @Generated for :compileJava. But I do see it for :javadoc. But in the example @Generated is broken in :compileJava, even if depending on a grpc dep that built fine (e.g., grpc-testing-proto, but installed using Java 8). :-/
@onesea, I'd suggest adding a dependency on javax.annotation:javax.annotation-api for the moment. It's possible to pass --add-modules java.xml.ws.annotation, but it seems it might cause more problems than it solves.
/**
*/
@javax.annotation.processing.Generated(
value = "by gRPC proto compiler",
comments = "Source: src/main/protobuf/command_server.proto")
public final class CommandServerGrpc {
private CommandServerGrpc() {}
[...]
And the Bazel build on Java 9 just works:
$ bazel --host_javabase=/usr/lib64/jvm/java-9-openjdk build --javacopt='--release 9' --java_toolchain=@bazel_tools//tools/jdk:toolchain_jdk9 src:bazel
[...]
INFO: From Compiling Java headers src/main/java/com/google/devtools/build/lib/worker/libworker-hjar.jar (16 files):
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.protobuf.UnsafeUtil (file:/home/davido/.cache/bazel/_bazel_davido/install/5906941a530f40a3f4749e5cfd148312/_embedded_binaries/embedded_tools/tools/jdk/turbine_deploy.jar) to field java.nio.Buffer.address
WARNING: Please consider reporting this to the maintainers of com.google.protobuf.UnsafeUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
INFO: From Building src/main/java/com/google/devtools/build/lib/libbazel-main-class.jar (4 source files) and running annotation processors (OptionProcessor):
warning: Supported source version 'RELEASE_8' from annotation processor 'com.google.devtools.common.options.processor.OptionProcessor' less than -source '1.9'
Target //src:bazel up-to-date:
bazel-bin/src/bazel
INFO: Elapsed time: 149.130s, Critical Path: 111.80s
INFO: Build completed successfully, 1986 total actions
@ejona86 As suggested, we added dependency to bazel on javax.annotation and added this as dependency to gRPC in Bazel tool chain, in: [1]. However, it was pointed out in the review, that this problem is going to be fixed upstream? Just wondering, as you said in comment to this issue, that you rather prefer that gRPC users will fix that problem?
If you are planning to address that problem upstream, do you have any time frame? I'm asking because this issue is very last issue, for full JDK 9 support in Bazel.
I'd have no problem adding the dependency to java_grpc_library. It's been done for Blaze internally, for instance. I simply didn't think about it when I fixed up gradle+Java 9.
What's the easiest way to test out Bazel+Java 9? It should be as easy as adding a line to added_deps. @davido, if you have a working Bazel+Java 9 environment, I'd be happy to accept a PR.
Activity
ejona86 commentedon Oct 30, 2017
That class exists in Java 9: https://docs.oracle.com/javase/8/docs/api/javax/annotation/Generated.html . It seems like the problem is with an example that isn't maintained here.
[-]java 9 not supported yet?[/-][+]Java 9: cannot find symbol javax.annotation.Generated[/+]Upgrade to Gradle 4.3
ejona86 commentedon Oct 30, 2017
Okay... I've now run into this as well for our example after #3637.
ejona86 commentedon Oct 30, 2017
For gRPC's build, after #3633 I don't see a problem with
@Generatedfor :compileJava. But I do see it for :javadoc. But in the example@Generatedis broken in :compileJava, even if depending on a grpc dep that built fine (e.g., grpc-testing-proto, but installed using Java 8). :-/ejona86 commentedon Oct 30, 2017
@onesea, I'd suggest adding a dependency on
javax.annotation:javax.annotation-apifor the moment. It's possible to pass--add-modules java.xml.ws.annotation, but it seems it might cause more problems than it solves.Upgrade to Gradle 4.3
davido commentedon Mar 8, 2018
I run into the same problem while working on Bazel build with Java 9: bazelbuild/bazel#4709.
davido commentedon Mar 8, 2018
The way it was fixed in other java based libraries, like
auto-common,auto-valueanddagger, is to dynamically select the right annotation to use:javax.annotation.processing.Generatedjavax.annotation.GeneratedSee e.g.: google/auto@f04406c, google/dagger#882.
ejona86 commentedon Mar 8, 2018
@davido, dynamic selection doesn't really seem to be a solution except for annotation processors.
davido commentedon Mar 8, 2018
@ejona86 The other two options would be to detect the Java runtime or pass explicit option to gRpc compiler, a lá:
--release 9or similar?davido commentedon Mar 8, 2018
I was able to patch gRpc compiler in Bazel tree, with this one liner:
With this, the generated source is:
And the Bazel build on Java 9 just works:
Support building bazel with Java 9
Patch gRpc to use Java 9 @generated annotation
14 remaining items
gRpc: Remove non supported @generated annotation for Java 9
Add javax.annotations to Bazel's third_party
Add javax.annotations to Bazel's third_party
davido commentedon Apr 9, 2018
@ejona86 As suggested, we added dependency to bazel on
javax.annotationand added this as dependency to gRPC in Bazel tool chain, in: [1]. However, it was pointed out in the review, that this problem is going to be fixed upstream? Just wondering, as you said in comment to this issue, that you rather prefer that gRPC users will fix that problem?If you are planning to address that problem upstream, do you have any time frame? I'm asking because this issue is very last issue, for full JDK 9 support in Bazel.
ejona86 commentedon Apr 9, 2018
I'd have no problem adding the dependency to java_grpc_library. It's been done for Blaze internally, for instance. I simply didn't think about it when I fixed up gradle+Java 9.
What's the easiest way to test out Bazel+Java 9? It should be as easy as adding a line to
added_deps. @davido, if you have a working Bazel+Java 9 environment, I'd be happy to accept a PR.davido commentedon Apr 9, 2018
The easiest way to reproduce the breakage on Bazel+Java 9, is to run this command in
grpc-java:I'm working on a fix and will upload a PR in a moment.
Bazel: Fix compilation in Java 9
Add javax.annotations to Bazel's third_party
Add a dependency on javax-annotations to java_grpc_library
Add a dependency on javax-annotations to java_grpc_library
Bazel: Fix compilation in Java 9