Skip to content

Transitive Koin Modules are not aggregated #326

@af-jul

Description

@af-jul

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 / @ComponentScan annotation to aggregate other Gradle modules Koin modules just like @KoinApplication does. Or I would expect@KoinApplication to discover all transitive Koin modules.
  • KOIN_CONFIG_CHECK to 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-bom version 4.1.1
  • koin-annotations-bom version 2.3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions