InsertKoinIO / koin-annotations

Koin Annotations - About Koin - a pragmatic lightweight dependency injection framework for Kotlin & Kotlin Multiplatform insert-koin.io
https://insert-koin.io
Apache License 2.0
163 stars 44 forks source link

KMP not work #175

Open springeye opened 1 month ago

springeye commented 1 month ago

Describe the bug

To Reproduce I followed the documentation https://insert-koin.io/docs/reference/koin-annotations/kmp configuration but it doesn't work properly

e: [ksp] --> Missing Definition type 'com.github.springeye.snote.di.DIFactory' for 'com.github.springeye.snote.di.privateAppDatabase'. Fix your configuration to define type 'DIFactory'.
e: Error occurred in KSP, check log for detail

Expected behavior sp can build the code normally

Koin project used and used version (please complete the following information): koin-bom = "4.0.0" koin-annotations = "1.4.0-RC4"

// KSP Tasks
dependencies {
    add("kspCommonMainMetadata",libs.koin.ksp.compiler)
    add("kspAndroid", libs.koin.ksp.compiler)
    add("kspIosX64", libs.koin.ksp.compiler)
    add("kspIosArm64", libs.koin.ksp.compiler)
    add("kspIosSimulatorArm64",libs.koin.ksp.compiler)
    add("kspDesktop",libs.koin.ksp.compiler)

    //room don‘t add kspCommonMainMetadata
//    add("kspCommonMainMetadata",libs.androidx.room.compiler)
    add("kspAndroid", libs.androidx.room.compiler)
    add("kspIosX64", libs.androidx.room.compiler)
    add("kspIosArm64", libs.androidx.room.compiler)
    add("kspIosSimulatorArm64",libs.androidx.room.compiler)
    add("kspDesktop",libs.androidx.room.compiler)

}

project.tasks.withType(KotlinCompilationTask::class.java).configureEach {
    if(name != "kspCommonMainKotlinMetadata") {
        dependsOn("kspCommonMainKotlinMetadata")
    }
}

ksp{
    arg("KOIN_CONFIG_CHECK","true")
}

commonMain/kotlin/AppModule.kt

@ComponentScan("com.github.springeye")
//@ComponentScan
@Module
class AppModule {
    @Single
    fun privateAppDatabase(factory:DIFactory):AppDatabase{
        return factory.createRoomDatabase()
    }
}

commonMain/kotlin/DIFactory.kt

expect class DIFactory {
    fun getPlatform(): Platform
    fun createRoomDatabase(): AppDatabase
}

desktopMain/kotlin/DIFactory.desktop.kt

@Single
actual class DIFactory {
    actual fun createRoomDatabase(): AppDatabase {
        return getRoomDatabase(getDatabaseBuilder())
    }

    actual fun getPlatform(): Platform {
        return JVMPlatform()
    }
}
arnaudgiuliani commented 1 month ago

here you can't use Koin 4.0 yet with KA 1.4.0