MergeModules

@Target(allowedTargets = [AnnotationTarget.CLASS])
annotation class MergeModules(val scope: KClass<*>, val includes: Array<KClass<*>> = [], val subcomponents: Array<KClass<*>> = [], val exclude: Array<KClass<*>> = [])

Marks a Dagger module to merge all contributed Dagger modules for the given scope. This is a subset of what MergeComponent and MergeSubcomponent are doing. Use this annotation instead of @Module in your module. The Kotlin compiler plugin will add the @Module annotation to this class. The parameters includes and subcomponents are preserved in the @Module annotation.

This annotation is useful if you can't use MergeComponent and MergeSubcomponent directly for your Dagger component. The Dagger modules annotated with this annotation serve as a composite module.

@MergeModules(AppScope::class)
abstract class CompositeAppModule

One common scenario where this annotation is used is when you want to use javac and not KAPT for compiling your Dagger components. The recommendation there is to add an extra Gradle module that merges modules. Your Dagger component must manually include this module using this annotation.

// Gradle Module A.
@MergeModules(AppScope::class)
abstract class CompositeAppModule

// Gradle Module B, note that this is Java and not Kotlin.
@Component(modules = CompositeAppModule.class)
public interface AppComponent {}

It's possible to exclude any automatically added Dagger module with the exclude parameter if needed.

@MergeModules(
scope = AppScope::class,
exclude = [
DaggerModule::class
]
)
abstract class CompositeAppModule

Properties

Link copied to clipboard

List of bindings, multibindings and modules that are contributed to the same scope, but should be excluded from the merged module.

Link copied to clipboard

List of Dagger modules that should be manually included in the merged module and aren't automatically contributed.

Link copied to clipboard
val scope: KClass<*>

The scope used to find all contributed bindings, multibindings and modules, which should be included in this merged module.

Link copied to clipboard

List of subcomponent annotated classes which should be children of the component in which this module is installed.