-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Unused import of javax.annotation.Generated breaks annotation processing on JDK9 with Jigsaw #880
Comments
I believe 772374b should take care of this (and will be in the next release) |
Hi! No, it won't solve any problem, because the application will still have two "modules" that are trying to write to the same package In addition, adding a dependency on JSR-250 makes little sense for a library like Dagger, because these annotations are JavaEE-specific (except The right way to fix it is presented above:
I'm looking forward to your feedback. |
What do you mean that
I don't believe we are writing anything to that package? Are you saying that the jsr250 jar "writes" to that package, which is sealed? |
Yes. In Jigsaw, each package can be owned by exactly one module. The problem with
Now, suppose that you have an existing application that depends both on module com.example.foo {
requires jsr250.api;
requires jsr305;
} Both dependencies are not modularized yet, so Java turns them into automatic modules, and you have to specify both of them in your module descriptor. However, if you do this, Java refuses to compile and run the application, because you have a package split - both modules try to add annotations to the same package
With Dagger, the situation is very similar. Dagger puts There is a way to workaround the problem by using
As you can see, it's not very convenient, because you must know the physical filesystem path to JSR-305 JAR, and you must actually hardcode them both in your build script, and your run script. I hope that this information is helpful. Meanwhile, I managed to create a pull request with the necessary changes. You can try this out with this example Dagger application: https://github.com/zyxist/dagger-example-app/tree/jigsaw-edition |
Hello, has anyone looked at the PR? |
I created a Pull Request that fixes this issue 16 days ago: #882 - has anyone looked at it? Any ETA for merging it and improving Dagger cooperation with JDK9? |
Why haven't anyone looked at this? The solution is literally right here |
Things are a bit more complicated - I don't believe the tests pass on that PR. I have something mostly working, but we still rely on I added a version of this annotation to ErrorProne (google/error-prone@7967165) which will be in their next release. Once that's in, we can migrate to that and drop the jsr250 dep, prefer javax.annotation.processing.Generated when it's available, and fully fix this. |
Now that the issue on error-pone is closed and 2.1.3 has been released two days ago: When can we expect a new Dagger release that fixes this issue? Thank you! 😁 |
Very shortly!
…On Thu, Nov 30, 2017, 8:13 AM Tobias Hagemann ***@***.***> wrote:
Now that the issue on error-pone is closed and 2.1.3 has been released two
days ago: When can we expect a new Dagger release that fixes this issue?
Thank you! 😁
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#880 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAwY3fp8PpKylPpW3u2gsyT6rt8fG7XZks5s7qnmgaJpZM4Pg7LH>
.
|
So, we are running into this issue on Java 9, in Gerrit Code Review, because we use I wrote this issue upstream, but I affraid that rules_closure can't help us until this issue is sorted out in Dagger? |
Something like this diff: [1] should fix it? |
Fixes #880 Closes #882 RELNOTES=Remove dependency on JSR 305 annotations ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=178784068
We need to upgrade rules_closure tools to be able to build with Java 9. That's because rules_closure depends on dagger 2 and auto-common and auto-value, that need to be updated to not depend on legacy annotations (that are not available on Java 9). Moreover, latest rules_closure switched to building protobuf library from the sources, creating the next problem: Protobuf doesn't support Java 9 yet. That was fixed only on master, so that we need to update rules_closure to consume the protobuf dependency from HEAD. See these issues for more background: [1],[2],[3],[4]. [1] google/auto#560 [2] bazelbuild/rules_closure#234 [3] google/dagger#880 [4] protocolbuffers/protobuf#4256 Bug: Issue 7958 Change-Id: I56f3b6101e06bd678b4e42d3a9d52157963513aa
Hello!
Today, I tried to write a modular JDK9 application with Dagger. Unfortunately, it turned out to be impossible without hacks. The problem is that the file
SourceFileGenerator.java
contains an unused import ofjavax.annotation.Generated
.This annotation is a part of
java.xml.ws.annotation
module, which is not loaded by default and is deprecated (to be removed in future Java versions). Historically, it was incorrectly placed in a package together with Java EE annotations. Furthermore, there exist several crappy JSR-305 JAR-s used by many libraries, that also add new annotations to the same package. In Jigsaw, the package can be owned by only one module. Java 9 refuses to compile an appplication and run it, if there are two modules that contain the same package.Now, to actually build Dagger modular application, we need to use some hacks. First of all, if we have any JSR-305 in our dependency list, we need to physically copy the JAR somewhere and use
--patch-module
compiler flag:The second thing is to enable that module explicitly:
And, configure the build system to exclude all the possible variants of jsr305 (Gradle example below):
However, we're not done yet. The annotation processor seems to ignore the flag
--add-modules
(and--add-reads
,--add-open
, etc.), which causes the following compiler error:As a workaround, we need to use
javax.annotation:jsr250-api:1.0
dependency for annotation processors. Below, there's a configuration for Gradle:Now Dagger is generating the code, but to make it work, we must modify our
module-info.java
files to add the dependency on the deprecatedjava.xml.ws.annotation
:As you can see, using Dagger is pretty complicated :).
You can do the following things to fix it:
SourceFileGenerator.java
(the code is already refering to the annotation as a String).javax.annotation.processing.Generated
which shall be used instead (module:java.compiler
). So, your code generator can work like this:javax.annotation.processing.Generated
is loaded, generate the output code with this annotation,javax.annotation.Generated
is loaded, use it,The changes are backward compatible.
The text was updated successfully, but these errors were encountered: