-
Notifications
You must be signed in to change notification settings - Fork 213
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
"error: [RefersToDaggerCodegen] Don't refer to Dagger's internal or generated code" flagged by error prone 2.3.4 #321
Comments
Interestingly, If I apply this patch: [1] to dagger@HEAD repository itself, I can reproduce exactly the same breakage, but only because Dagger is using
//CC @ronshapiro |
That EP rule looks for |
@netdpb No idea. I wrote this issue upstream google/dagger#1831. |
What happens is that "javax.annotation" dependency is erroneously missing in kotlin build tool chain. As the consequence, Dagger cannot emit "Generated" annotation, and new EP version is flagging generated code as broken, as it cannot realized that the code itself is generated code. Will upload a fix in a moment. |
Fixes bazelbuild#321. Bazel/Dagger integration requires javax.annotation to be on the classpath to generate @generated annotation. Recent ErrorProne releases (started from 2.3.3) added new bug pattern: RefersToDaggerCodegen that is flagging the code as invalid, as it doesn't realized that the code is generated. Due to this problem, a previous attemt to bump EP version in Bazel was reverted. Fixing it would allow us to make another attempt to update EP version in Bazel.
Fixes bazelbuild#321. Bazel/Dagger integration requires javax.annotation to be on the classpath to generate @generated annotation. Recent ErrorProne releases (started from 2.3.3) added new bug pattern: RefersToDaggerCodegen that is flagging the code as invalid, as it doesn't realize that the code is generated. Due to this problem, a previous attemt to bump EP version in Bazel was reverted. Fixing it would allow us to make another attempt to update EP version in Bazel.
Fixes bazelbuild#321. Bazel/Dagger integration requires javax.annotation to be on the classpath to generate @generated annotation. Recent ErrorProne releases (started from 2.3.3) added new bug pattern: RefersToDaggerCodegen that is flagging the code as invalid, as it doesn't realize that the code is generated. Due to this problem, a previous attemt to bump EP version in Bazel was reverted. Fixing it would allow us to make another attempt to update EP version in Bazel. Test Plan: A. Involved approach: 1. Bump EP version to 2.3.4 2. Conduct custom java tools release with new EP version 3. Consume custom java tools release in WORKSPACE 4. Try to bulid rule_kotlin would fail with RefersToDaggerCodegen error B. Simple approach 1. Apply this patch 2. Build rules_kotlin 3. Confirm that this class: KotlinBuilderComponent_Module_ProvidePluginArgEncoderFactory is annotated with @generated annotation: Generated( value = "dagger.internal.codegen.ComponentProcessor", comments = "https://dagger.dev" ) @SuppressWarnings({ "unchecked", "rawtypes" }) public final class KotlinBuilderComponent_Module_ProvidePluginArgEncoderFactory [...]
Fixes bazelbuild#321. Bazel/Dagger integration requires javax.annotation to be on the classpath to generate @generated annotation. Recent ErrorProne releases (started from 2.3.3) added new bug pattern: RefersToDaggerCodegen that is flagging the code as invalid, as it doesn't realize that the code is generated. Due to this problem, a previous attemt to bump EP version in Bazel was reverted. Fixing it would allow us to make another attempt to update EP version in Bazel. Test Plan: A. Involved approach: 1. Bump EP version to 2.3.4 2. Conduct custom java tools release with new EP version 3. Consume custom java tools release in WORKSPACE 4. Try to bulid rule_kotlin would fail with RefersToDaggerCodegen error B. Simple approach 1. Apply this patch 2. Build rules_kotlin 3. Confirm that this class: KotlinBuilderComponent_Module_ProvidePluginArgEncoderFactory is annotated with @generated annotation: @generated( value = "dagger.internal.codegen.ComponentProcessor", comments = "https://dagger.dev" ) @SuppressWarnings({ "unchecked", "rawtypes" }) public final class KotlinBuilderComponent_Module_ProvidePluginArgEncoderFactory [...]
Fixes bazelbuild#321. Bazel/Dagger integration requires javax.annotation to be on the classpath to generate @generated annotation. Recent ErrorProne releases (started from 2.3.3) added new bug pattern: RefersToDaggerCodegen that is flagging the code as invalid, as it doesn't realize that the code is generated. Due to this problem, a previous attemt to bump EP version in Bazel was reverted. Fixing it would allow us to make another attempt to update EP version in Bazel. Test Plan: A. Involved approach: 1. Bump EP version to 2.3.4 in Bazel 2. Conduct custom java tools release with new EP version 3. Consume custom java tools release in WORKSPACE in rules_kotlin 4. Trying to bulid rules_kotlin would fail with RefersToDaggerCodegen error B. Simple approach: 1. Apply this patch 2. Build rules_kotlin 3. Confirm that this class: KotlinBuilderComponent_Module_ProvidePluginArgEncoderFactory is annotated with @generated annotation: @generated( value = "dagger.internal.codegen.ComponentProcessor", comments = "https://dagger.dev" ) @SuppressWarnings({ "unchecked", "rawtypes" }) public final class KotlinBuilderComponent_Module_ProvidePluginArgEncoderFactory [...]
I see - so this is an issue with building the builder itself. We can add this, but your issue might be resolved automatically by upgrading to 1.4.0 (and its release candidates) as the builder is shipped as a pre-built binary, so you should never execute the code path you're hitting. What version of the rules were you using? |
I don't use rules_kotlin. I try to upgrade EP in Bazel. For that I bumped EP version to 2.3.4, conducted new java_tools release, upgraded java_tools in rules_kotlin and building with custom javatoolchain rules_kotlin from HEAD with this new EP and the build is failing. Let me know if you need a reproducer. |
Fixes bazelbuild#321. Dagger transitively depends on this depedency and it is already fetched by rules_jvm_external, so that it can be used and recently added explicit dependency on javax.annotation can be removed.
I figured out what happens. kotlin builder is built for host configuration. Bazel is using remote Java 11. That why bootclasspath does not contain
The failing compilation is using -source 8 -target 8 with a JDK 11 -bootclasspath (Bazel remote JDK 11 for host configuration). So AutoAnnotation is trying to use |
We cannot upgrade Error Prone in Bazel, because of this issue. The last attempt to bump EP in Bazel to 2.3.3: [1], [2], [3] was reverted because of this breakage.
Recent EP releases added new bug pattern checks that Bazel eco system would like to benefit from.
I've re-done EP version upgrade in Bazel in this PR: [4].
However, the same issue as in EP 2.3.3 shows up, when trying to build
src/main/...
target.I uploaded a reproducer to demonstrate the breakage: [5]. Note though, you need Linux machine, as I only published draft java_tool release with bumped EP version 2.3.4 on Linux platform:
I also wrote this issue upstream: [5].
[1] bazelbuild/bazel#9286
[2] bazelbuild/bazel#10023
[3] bazelbuild/bazel@d990746
[4] bazelbuild/bazel#11271
[5] #320
[6] google/error-prone#1599
The text was updated successfully, but these errors were encountered: