Roger Kreienbühl
07/07/2025, 5:48 AM@Single
:
package com.example.data.mapper
import org.koin.core.annotation.Single
@Single
class XyzDtoMapper {
...
}
I try to scan for this class with a module defined inside the server gradle module:
package com.example.di
import org.koin.core.annotation.ComponentScan
import org.koin.core.annotation.Module
@Module
@ComponentScan("com.example.data.mapper")
class MapperModule
Is such a Scan over multiple gradle modules possible, and if do, how can I achieve this?
The Mapper module is generated but the XyzDtoMapper
is not present in it.Kibet Theophilus
07/07/2025, 8:30 AMMantas Varnagiris
07/07/2025, 9:03 AMRoger Kreienbühl
07/07/2025, 9:52 AMKibet Theophilus
07/08/2025, 10:32 AMRoger Kreienbühl
07/08/2025, 11:12 AMSharedMapperModule
inside the shared gradle module:
@Module
@ComponentScan("dev.kreienbuehl.swissclimbing.data.mapper")
class SharedMapperModule
and changed MapperModule
inside the server as followed:
@Module(
includes = [
SharedMapperModule::class
]
)
@ComponentScan("dev.kreienbuehl.swissclimbing.data.mapper")
class MapperModule
What i didn't see anywhere in the docs was how to get the shared module to generate the generated koin files. I figured that out by investigating the example listed in the docs.
I had to add this to the `build.gradle.kts`of the shared module:
dependencies {
// KSP Tasks
add("kspCommonMainMetadata", libs.koin.ksp.compiler)
}
tasks.withType<KotlinCompile>().configureEach {
if (name != "kspCommonMainKotlinMetadata") {
dependsOn("kspCommonMainKotlinMetadata")
}
}
afterEvaluate {
tasks.filter {
it.name.contains("SourcesJar", true)
}.forEach {
println("SourceJarTask====>${it.name}")
it.dependsOn("kspCommonMainKotlinMetadata")
}
}
Don't know if this is the best way, but it works.Kibet Theophilus
07/08/2025, 11:52 AMRoger Kreienbühl
07/08/2025, 12:00 PMtasks.withType<KotlinCompile>().configureEach {
if (name != "kspCommonMainKotlinMetadata") {
dependsOn("kspCommonMainKotlinMetadata")
}
}
afterEvaluate {
tasks.filter {
it.name.contains("SourcesJar", true)
}.forEach {
println("SourceJarTask====>${it.name}")
it.dependsOn("kspCommonMainKotlinMetadata")
}
}
is not mentioned in it. Withoout it, the code was not generated in my case. In the linked example app https://github.com/InsertKoinIO/hello-kmp/tree/annotations
I found this as workaround instead of adding
dependencies {
// KSP Tasks
add("kspCommonMainMetadata", libs.koin.ksp.compiler)
}
but I needed both that it worked for the server.