question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Preemptive fail compilation when Multibinding can not be added to a Component

See original GitHub issue

Consider the following scenario:

image

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:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
vRallevcommented, Mar 4, 2021

The issue is that you use implementation instead of api dependencies. 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 using implementation incorrectly, that’s why you see this behavior. I suggest to take a look at this guide.

For example, in the feature module you have

@[Module ContributesTo(AppScope::class)]
interface Feature1FragmentModule

AppScope is coming from the base module. Since you expose the type to consumers, you should import the base module with an api dependency and not implementation.

I’m sorry, but everything works as expected and it’s an issue with your project.

0reactions
marcellogalhardocommented, Mar 5, 2021

Hm, thank you for the reference link and your time in the discussion. I read it and I agree with you, I’m overusing implementation for almost everything and should be using api in this case. Thank you again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot add instance of type 'MultiBinding' to a collection of ...
I was able to replicate your error in Visual Studio 2015. It does appear to be simply a bug with the XAML editor,...
Read more >
MultiBinding Converter doesn't update on change
All bindings work fine if i change <Textbox.Text> with a property with normal converter instead of multbinding hack. But when i do that...
Read more >
Considerations in adopting RHEL 9 Red Hat Enterprise Linux 9
The single language mode is not supported on RHEL 9. ... you can change the preemption mode of the kernel at boot or...
Read more >
Mastering Windows Presentation Foundation
Data Error: 17 : Cannot get 'Item[]' value (type ... application is also included within the Models component of the pattern. Care should...
Read more >
Silverlight - CodeProject
Learn how error reporting works and how to add it to you software in 3 simple steps. Not only is it easy for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found