koin-annotations
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
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:
- Build the linked sample repo - observe the
configurationModuleslist in generatedKoinAppGencom*file contains 2 modules and the App runs without issues.
val KoinApp.configurationModules : List<Module> get() = listOf(AppModule().module, SharedModule().module)
- Change KSP version to basically any above
2.1.20-1.0.32, for example2.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.
- To solve this, apply solution mentioned in https://github.com/google/ksp/issues/2442#issuecomment-3083733049 , by replacing
tasks.withType<KotlinCompilationTask<*>>().configureEachwithtasks.withType<KspAATask>().configureEach - The build is now successful, but
configurationModuleslist in generatedKoinAppGencom*file now contains onlyAppModule. TheSharedModulefrom 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.