Preemptive fail compilation when Multibinding can not be added to a Component
See original GitHub issueConsider the following scenario:

If :app module does not directly depend on library1, Dagger won’t fail the compilation as a map multi-binding will be resolved at runtime by a @MapKey and at the same time, Anvil won’t be able to contribute the multi-binding to :app component - which might cause a runtime exception. For cases where we don’t use multi-binding, Dagger will detect a binding is missing and fail the compilation rightfully. If necessary I can provide a small reproducible sample.
It would be beneficial if Anvil could alert us about this situation in a preemptive way and fail the compilation to avoid runtime
exceptions for Modules that have a valid contribution to scope, but the target MergeComponent can not be contributed to from that module.
This situation already happens (with Dagger multi-binding + @ContributesTo), but this enhancement will be extra helpful when combined with the new @ContributesMultibinding from #152.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)

Top Related StackOverflow Question
The issue is that you use
implementationinstead ofapidependencies. You’re explicitly telling Gradle not to add any dependencies to the compile classpath of downstream projects. You’re only adding the dependencies to the runtime classpath of your app. You’re actually usingimplementationincorrectly, that’s why you see this behavior. I suggest to take a look at this guide.For example, in the feature module you have
AppScopeis coming from the base module. Since you expose the type to consumers, you should import the base module with anapidependency and notimplementation.I’m sorry, but everything works as expected and it’s an issue with your project.
Hm, thank you for the reference link and your time in the discussion. I read it and I agree with you, I’m overusing
implementationfor almost everything and should be usingapiin this case. Thank you again.