-
-
Notifications
You must be signed in to change notification settings - Fork 68
Description
Describe the bug
Assume I have a Gradle module structure like the following where I have my app module which only depends on ui and data modules. These ui and data modules then depend on domain.
The culprit in the end is just a simple transitive Gradle module dependency :app --> :ui --> :domain.
The :data module mentioned here is just to showcase a related issue with KOIN_CONFIG_CHECK
:app
|--> :ui ----\
| |--> domain
|--> :data --/
The @KoinApplication in :app correctly aggregates the Koin module from :ui into the generated configurationModules. However it does not transitively include the Koin module from :domain. If I have a look at the generated code of the :ui Koin module, it does not include the :domain Koin module at all.
This leads to missing definitions and runtime crashes.
Interestingly, I am able to build the app even with ksp { arg("KOIN_CONFIG_CHECK","true") } enabled. It still crashes at runtime. I have KOIN_CONFIG_CHECK only enabled in my :app module. Due to the strict layer separation and dependency direction (ui --> domain <-- data) I cannot enable it in every module, because only when the app module aggregates everything, it can fulfill all dependencies.
To Reproduce
My Koin setup looks like the following
:app module:
@KoinApplication
object MyApp
// Koin generated
public val abc.MyApp.configurationModules : List<Module> get() = listOf(abc.ui.UiModule.module,
abc.data.DataModule.module):ui module:
@Module
@Configuration
@ComponentScan
object UiModule
// Koin generated
public val abc_ui_UiModule : Module get() = module {
viewModel() { _ -> abc.ui.MyViewModel(myUseCase=get() }
}:domain module:
@Module
@Configuration
@ComponentScan
object DomainModule
// Koin generated
public val abc_domain_DomainModule : Module get() = module {
factory() { _ -> abc.domain.MyUseCase(myRepository=get())}
}:data module:
@Module
@Configuration
@ComponentScan
object DataModule
// Koin generated
public val abc_data_DataModule : Module get() = module {
single() { _ -> abc.data.MyRepositoryImpl()} bind(abc.domain.MyRepository::class)
}Expected behavior
I would expect
- the
@Module/@ComponentScanannotation to aggregate other Gradle modules Koin modules just like@KoinApplicationdoes. Or I would expect@KoinApplicationto discover all transitive Koin modules. KOIN_CONFIG_CHECKto work as expected when working with transitive modules
I do not want to add an explicit dependency to :domain into my :app module just to achieve auto-aggregation.
Koin project used and used version (please complete the following information):
koin-bomversion4.1.1koin-annotations-bomversion2.3.1