Subcomponents parameter of Module annotation doesn't seem to work. #60
-
This is a small issue, but the solution wasn't entirely obvious so I thought I'd share my experience and see if something could be improved. It seems like the move to KSP has changed the mechanism of how Subcomponents are linked to their parents. Moving to this fork required the inner Builder interface to use the Builder interface from its parent interface. e.g. MergeComponent now requires In my case, we have an AppComponent and a SubComponent called the InitializedComponent. They are both defined in the @MergeComponent(AppScope::class)
interface AppComponent {
fun inject(mainActivity: MainActivity)
@Component.Builder
interface Builder {
@BindsInstance
fun application(application: Application): Builder
fun build(): AppComponent
}
}
@MergeSubcomponent(scope = InitializedScope::class)
interface InitializedComponent : InjectorsComponent {
@Subcomponent.Factory
interface Factory {
fun build(): InitializedComponent
}
} On the base version of Anvil, we then "link" the two components by creating a module like this and using the @[Module(subcomponents = [InitializedComponent::class]) ContributesTo(AppScope::class)]
object InitializerModule {
@Provides
fun provideInitializer(factory: InitializedComponent.Factory): Initializer {
return Initializer(factory)
}
} However, because of the requirement that the Factory (or Builder) must be annotated with the new annotation, we now get this KSP error
The workaround is to add Thanks for working on this! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yeah this is one of the cases described at the bottom of this section: https:/ZacSweers/anvil/blob/main/FORK.md#2-ksp-component-merging Anywhere that was not processed by anvil before and referenced anvil merged types need to be updated to use the generated @[Module(subcomponents = [MergedInitializedComponent::class]) ContributesTo(AppScope::class)]
object InitializerModule {
@Provides
fun provideInitializer(factory: InitializedComponent.Factory): Initializer {
return Initializer(factory)
}
} |
Beta Was this translation helpful? Give feedback.
Yeah this is one of the cases described at the bottom of this section: https:/ZacSweers/anvil/blob/main/FORK.md#2-ksp-component-merging
Anywhere that was not processed by anvil before and referenced anvil merged types need to be updated to use the generated
Merged*
class instead. In your case, something like this