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

Modules discovery doesn't work for KSP later than 2.1.20-1.0.32 in multi-module KMP project

Open fgrzeskowiak opened this issue 1 month ago • 7 comments
trafficstars

Describe the bug

KSP 2.1.20-1.0.32 is the last version in which the automatic modules discovery using @KoinApplication works properly in multi-module Multiplatform project. In any later version the build fails. After applying a possible fix, the build succeeds, but the configurationModules list in the generated KoinAppGencom* file doesn't include Koin Modules from other Gradle modules anymore.

I prepared a simple repo, which can be used to illustrate the issue. It contains 2 Gradle modules: composeApp and shared. https://github.com/fgrzeskowiak/koin-annotations-ksp-issue

To Reproduce

Steps to reproduce the behavior:

  1. Build the linked sample repo - observe the configurationModules list in generated KoinAppGencom* file contains 2 modules and the App runs without issues.
val KoinApp.configurationModules : List<Module> get() = listOf(AppModule().module, SharedModule().module)
  1. Change KSP version to basically any above 2.1.20-1.0.32, for example 2.1.20-2.0.0 - the build starts failing with error saying:
Task ':shared:kspAndroidMain' uses this output of task ':shared:kspCommonMainKotlinMetadata' without declaring an explicit or implicit dependency.
  1. To solve this, apply solution mentioned in https://github.com/google/ksp/issues/2442#issuecomment-3083733049 , by replacing tasks.withType<KotlinCompilationTask<*>>().configureEach with tasks.withType<KspAATask>().configureEach
  2. The build is now successful, but configurationModules list in generated KoinAppGencom* file now contains only AppModule. The SharedModule from a separate Gradle module was not found, resulting in App crash.
val KoinApp.configurationModules : List<Module> get() = listOf(AppModule().module)

The only way to make it work again is to manually reference Koin modules from different Gradle modules as parameters to @KoinApplication annotation.

Expected behavior

Modules discovery from other Gradle modules should work for newer versions of KSP as well. Since KSP version is tightly connected with Kotlin version, this issue basically limits KMP projects with Koin Annotations to be stuck on Kotlin 2.1.20.

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

koin-core version 4.1.1 koin-annotations version 2.2.0

Possible causes

Release notes for KSP 2.1.20-2.0.0 say that from this version KSP2 is enabled by default, so I would suspect the problem might be connected to this and to the replacement of KotlinCompilationTask with KspAATask.

fgrzeskowiak avatar Oct 16 '25 20:10 fgrzeskowiak