-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
This issue stemmed from #1714 where @dagger.Module was used in a dependency without running the Dagger compiler. This ends up failing with an error like
Error: FooModule_provodeFooFactory does not exist
While the solution is simple -- add the dagger compiler dependency to the library where FooModule is defined -- the error message isn't obvious. Thus, the request here is if we can detect this in Dagger and throw a more specific error that tells the user they forgot the Dagger compiler dependency in a downstream dependency.
Note that this can be tricky because there are valid cases where the factory is only missing from the classpath temporarily and will be generated in the subsequent round. Thus we can't just fail immediately in all cases. There's two solutions to this that I can think of:
Option 1:
Detect if the module is from a library (Origin.JAVA_LIB or Origin.KOTLIN_LIB) and fail if the factory isn't on the classpath.
- Pros: We can fail immediately when we detect this.
- Cons: I think this information is only available in KSP, not Javac.
Option 2
Defer processing until the next round if any module factory is missing.
- Pros: Works in all cases.
- Cons: Could be costly to delay processing since it means some amount of work needs to be recomputed.
I should also mention that we decided against generating the module's factory in these cases. You may wonder why since we already do this for @Inject classes, but even in those cases it can run into issues when multiple components try to generate the same factory. Also, @Inject is different because the annotation is not owned by Dagger and can reasonably be used by other DI libraries so there's valid reasons to no run Dagger's processor over those sources.