koin-annotations icon indicating copy to clipboard operation
koin-annotations copied to clipboard

`KOIN_CONFIG_CHECK` Fails to Discover Included Modules from Other Gradle Modules

Open iribuda opened this issue 1 month ago • 6 comments
trafficstars

Describe the bug

When KOIN_CONFIG_CHECK is enabled for Koin compile-time checks, the compilation fails with:

[ksp] java.lang.IllegalStateException: can't find module metadata for [...] in current modules or any meta tags

All koin modules declare the required annotations: @Module, @Configuration, and @ComponentScan. The root DI module tries to aggregate feature modules via @Module(includes = [...]). Modules declared in the same Gradle module are discovered, but modules declared in other Gradle modules are not. When ModuleA includes ModuleB (where ModuleA, ModuleB both live in different Gradle modules), the build fails because KSP/Koin cannot find the module metadata for ModuleB — nested/included modules from other Gradle modules are not seen during the KOIN_CONFIG_CHECK validation.

This happens even though the KSP-generated module metadata files are present (both ksp/android and ksp/metadata outputs exist for the modules). Disabling KOIN_CONFIG_CHECK (setting it to "false") allows the project to compile and run normally. The failure appears to be related to cross-module metadata discovery — each Gradle module is processed independently by KSP and the checker cannot locate metadata from other modules (?)

This looks related to https://github.com/InsertKoinIO/koin/issues/2163 but occurs with current KSP/Koin annotation setup in a multi-module project.

To Reproduce

Multi-module KMP Project with several feature/data modules and an app module.

Project Structure:

  • :domain — declares a repository interface.
  • :network-api — declares a network qualifier and a small network module that provides an HttpClient.
  • :data — implements the repository and declares a data module that includes the network module.
  • :app-di — root DI module that includes the data module only.

Configuration:

  • All modules have KSP plugin and dependencies:
kotlin {
    sourceSets {
        commonMain.dependencies {
            implementation(platform("io.insert-koin:koin-bom:4.1.1"))
            implementation(platform("io.insert-koin:koin-annotations-bom:2.2.0-RC4"))
            implementation("io.insert-koin:koin-core:4.1.1")
            implementation("io.insert-koin:koin-annotations:2.2.0-RC4")
        }
    }
}

dependencies {
    implementation(platform("io.insert-koin:koin-annotations-bom:2.2.0-RC4"))
    kspCommonMainMetadata("io.insert-koin:koin-ksp:2.2.0-RC4")
    kspAndroid("io.insert-koin:koin-ksp:2.2.0-RC4")
    kspIosX64("io.insert-koin:koin-ksp:2.2.0-RC4")
    kspIosArm64("io.insert-koin:koin-ksp:2.2.0-RC4")
    kspIosSimulatorArm64("io.insert-koin:koin-ksp:2.2.0-RC4")
}
  • :data depends on :network-api and :domain
  • :app-di depends on :data only.
  • ksp {arg("KOIN_CONFIG_CHECK", "true")} is set in :app-di build.gradle.kts

Expected behavior

When KOIN_CONFIG_CHECK is enabled, the compile-time checker should aggregate/consume module metadata from all project modules (or otherwise accept metadata produced by KSP for dependent modules) and perform the configuration checks successfully. Enabling the check should not fail purely because metadata was generated from other Gradle modules processed separately.

Koin project used and used version (please complete the following information):

  • koin-annotations-bom, koin-ksp-compiler: "2.2.0-RC4"
  • koin-core: "4.1.1"
  • Kotlin: "2.1.21"
  • agp: "8.9.2"
  • ksp: "2.1.21-2.0.2"

Additional

  • Observed generated files exist under build/generated/ksp/android and build/generated/ksp/metadata for each module, yet the checker reports missing metadata across modules.

Request

Please advise whether:

  • Koin annotations expect an explicit aggregator module or a specific build configuration for multi-module projects, or
  • Koin annotations can be updated to look up ksp/metadata outputs or gradle metadata to find generated modules across module boundaries, or
  • there is a recommended project setup (ksp/metadata config, meta tags, or Gradle ordering) to make KOIN_CONFIG_CHECK work in multi-module projects without adding direct dependencies from app to every feature module.

iribuda avatar Oct 07 '25 14:10 iribuda