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
Cannot resolve third party annotation with Dagger 2.41. #3256
Comments
We should only be validating that annotation in the final app module if you aren't running the Dagger processor in the library module where the class is defined (see InjectValidator.java). Can you check whether you have the Dagger processor running in the library where |
We're not running the annotation processor in this module. Could Dagger be less strict about requiring all types to be present on the compile classpath? That's definitely a behavior change from previous versions. |
Is there a reason you cannot or don't want to run the annotation processor in that module?
Yes, we mention it a bit in the 2.41 release notes. You can go back to the previous behavior using
In general, no, since we want to guarantee correctness. However, there are a few (relatively rare) cases such as this one where the validation is not technically needed for correctness per-se (e.g. in this case it's just used to check for incorrect placement of qualifiers on the constructor). At the time, we discussed being less strict for this case but decided to keep it mandatory assuming most classpath issues could be avoided by running the annotation processor in the library itself. I think we'd be willing to reconsider making these cases less strict (or at least add a compiler option to do so) when the validation is not needed for correctness. Still, it would be nice to know what reasons there are to not run Dagger's annotation processor in this case, so please let us know. |
Also, just to clarify, we don't require all types to be present on the compile classpath, only what is needed for us to perform our validation. In particular, in this case we were looking for misplaced qualifiers on the constructor, but we can't tell if |
Thanks for the long explanation and shame on me for not reading the release notes. What you consider as a bug in the old version is actually something we relied on. I can explain our use case better. We have a strict separation of TL;DR for not enabling the Dagger annotation processor is KAPT and the higher build time. It matters with thousands of modules. The flag to opt-out of this behavior sounds like a good solution for us, but it worries me that you plan to remove it soon. |
So I think this is going to be a requirement for Dagger that we won't be able to be too flexible on, otherwise we run the risk of missing critical annotations and causing functional issues. Annotations that are in places where we might reasonably care about them will need to be on the classpath for the processor so it can know if they affect functionality or not. Running the processor over the class is an optimization because we already process it once in the library, so we can pass information down the root, so we don't actually need those classes on the classpath anymore. With that said, I think there are a few options:
Hopefully one of those options works for your case. |
I totally understand the reasoning. We might go with option 2 or 3. Thanks for all the input! |
We have custom annotations in our codebase similar to this:
This type
MockAccountStatusService
is being used in our dependency graph.With Dagger 2.41 (currently using 2.39.1) we get following error in a module downstream:
It is correct, the annotation isn't on the compile classpath of the final app module where this error is thrown. But in my opinion Dagger should now try to resolve the annotation or at least ignore it if it fails to resolve. Is this new behavior expected?
The text was updated successfully, but these errors were encountered: