-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Java 9: cannot find symbol javax.annotation.Generated #3633
Comments
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. |
Okay... I've now run into this as well for our example after #3637. |
For gRPC's build, after #3633 I don't see a problem with |
@onesea, I'd suggest adding a dependency on |
I run into the same problem while working on Bazel build with Java 9: bazelbuild/bazel#4709. |
The way it was fixed in other java based libraries, like
See e.g.: google/auto@f04406c, google/dagger#882. |
@davido, dynamic selection doesn't really seem to be a solution except for annotation processors. |
@ejona86 The other two options would be to detect the Java runtime or pass explicit option to gRpc compiler, a lá: |
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:
|
Fixes: bazelbuild#3410, bazelbuild#4709. To build bazel with Java 9 issue: $ bazel --host_javabase=/usr/lib64/jvm/java-9-openjdk build \ --javacopt='--release 9' \ --java_toolchain=@bazel_tools//tools/jdk:toolchain_jdk9 \ src:bazel This still doesn't work due to gRpc dependency on Java 8 specific @javax.annotation.Generated annotation: [1]. [1] grpc/grpc-java#3633 Change-Id: Ic529e222344dc894e9d6b853a9551c7a19a52697
This is a workaround for: [1]. [1] grpc/grpc-java#3633 Change-Id: I07ebacaa400022f6ff3e2396cf236e93bef12554
@davido, as I said in an earlier comment, I recommend you to depend on |
@ejona86 Thanks, I noticed your commentm and I did it indeed for gerrit (before |
@davido, I don't think the two annotations are interchangeable. At the very least
|
Fixes: [1]. [1] grpc/grpc-java#3633 Change-Id: I07ebacaa400022f6ff3e2396cf236e93bef12554
Technically speaking, there is no statement in JDK API docs that At the same time, when I look at it right now, I see that this might be a design issue in Java API. From the usage perspective, the annotation for marking generated code has little to do with accessing compiler API. |
One disadvantage to remove the @cushon, @eamonnmcmanus, @ronshapiro: Do you have any comments on this discussion as what would be the right course of action here? |
Adding the dependency to javax.annotation.Generated is likely to cause someone issues with Java 9's JPMS because the of the way the While it's true that the "new" version is in the "annotation processing" package, it is the canonical Generated annotation in Java 9. I think you could argue that But taking a step back - both annotations are source level. |
+1 The docs for I do not recommend using |
The first-line description of package javax.annotation.processing's Javadoc:
While I do agree that it could be used for other things, pulling in a dependency on all of
@cushon, everything I see for it isn't "deprecated and stop using it" it is "being removed; get it externally from the JDK". The Migration Documentation says it was removed because it was part of J2EE, not because it was bad to use. It also explicitly says in the "upgrade paths" (none of which are "migrate to another api"):
Why do you say that? In my mind, a much bigger source of trouble is thinking that we must use the new annotation with Java 9+ and we must use the old annotation with Java pre-9. That's simply unacceptable. |
Why? That's the approach we've been using for other code generators, so far successfully. If you see specific problems with it I'm interested to know what they are? |
Everything outside of java.se is going away, isn't it? It seems someone using jlink would notice, and it seems Oracle is pushing jlink pretty hard, since they're trying to discontinue the self-contained JRE. Although I guess the user can make that a compile-only dependency.
Aren't all the generators you're talking about annotation processors? Those are integrating with the JDK anyway. The new annotation seems like a convenience for annotation processors (as it can remove a dependency for them; and I would expect it helps prevent processors from stepping on each other's toes) and easy for such a processor to choose at runtime (it already has all the information it needs), transparent to the user. In our case we don't know the Java version that will be compiling the code. We could add an option, but that seems no easier for the user than an additional dependency (which is still a pain) and I reject the idea that we should need to know and generate different code (but I don't reject that it may be easier for our users if we do so). We've had a very strong policy of needing a "canonical" version of the generated code. There are no options. This was based on years of learning the folly of providing options with protobuf (and there's still lots of work to remove such options). Now, it's really only important that the class files are canonical. But at the same time I've not noticed any mention of a problem that is solved by moving to I have found a parenthetical in JEP 320 mentioning migrating to javax.annotation.processing.Generated. With that in mind, I could understand potentially migrating to the Java 9 annotation after we require Java 9. But that would be years in the future. Right now I feel I'm more likely to remove the |
Right, since it's a source retention annotation it is not needed at runtime. Some build systems make this easier to configure than others. Realistically some users will probably end up including the dependency at runtime.
I agree that this change problematic. The decision to move the canonical
There are two parts to this: whether emitting For the first part, I don't have a strong opinion. We've seen people rely on For the second part, relying on the @javax.annotation.Nullable
@javax.annotation.Generated("")
class X {} Compiling with
Using
|
Fixes: [1]. [1] grpc/grpc-java#3633 Change-Id: I07ebacaa400022f6ff3e2396cf236e93bef12554
This library provides the @generated annotation, which is not available by default in JDK 9 (see http://openjdk.java.net/jeps/320). This will be used to work around grpc/grpc-java#3633. Change-Id: I7d6d9a6d6c44fe23818e093c6ecc97f557dd5a3e
This library provides the @generated annotation, which is not available by default in JDK 9 (see http://openjdk.java.net/jeps/320). This will be used to work around grpc/grpc-java#3633. Change-Id: I7d6d9a6d6c44fe23818e093c6ecc97f557dd5a3e
@ejona86 As suggested, we added dependency to bazel on 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 |
The easiest way to reproduce the breakage on Bazel+Java 9, is to run this command in
I'm working on a fix and will upload a PR in a moment. |
Fixes: grpc#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 library provides the @generated annotation, which is not available by default in JDK 9 (see http://openjdk.java.net/jeps/320). This will be used to work around grpc/grpc-java#3633. Change-Id: I7d6d9a6d6c44fe23818e093c6ecc97f557dd5a3e
to work around grpc/grpc-java#3633. Change-Id: I7623a3d2a26f91cd37cad3c3446c37ce6fbd0706
to work around grpc/grpc-java#3633. Change-Id: I7623a3d2a26f91cd37cad3c3446c37ce6fbd0706 Closes #5017.
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
/root/grpc-kotlin-hello/proto/src/main/java/io/grpc/examples/helloworld/GreeterGrpc.java:23: error: cannot find symbol
@javax.annotation.Generated(
^
symbol: class Generated
location: package javax.annotation
1 error
FAILURE: Build failed with an exception.
The text was updated successfully, but these errors were encountered: