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
123 stars 30 forks source link

Koin Annotation with KMP fails to generate the default Module without explicit package declaration #111

Closed Ynnck123 closed 5 months ago

Ynnck123 commented 5 months ago

Describe the bug As the title Koin Annotation implies, in a Kotlin Multiplatform project Koin Annotation fails to generate the default Module for classes without package declaration in the Kotlin folder.

To Reproduce Steps to reproduce the behavior:

  1. Setup Koin Annotations in a basic KMP project with Android and iOS target (probably doesn't matter)

  2. Have the following package structure in the commonMain module (so you place your files simply in ../kotlin like for example in the Compose Multiplatform for iOS and Android template project:

    image
  3. Create the SampleClass you can see above in the kotlin package:

    import org.koin.core.annotation.Single
    
    @Single
    class SampleClass
  4. Execute the Koin KSP compiler process / build the project

Expected behavior The Default.kt should properly contain the SampleClass definition

Actual behavior The build fails because the generated Default.kt file looks like the following:

package org.koin.ksp.generated

import org.koin.core.KoinApplication
import org.koin.core.module.Module
import org.koin.dsl.*

public fun KoinApplication.defaultModule(): KoinApplication = modules(defaultModule)
public val defaultModule : Module = module {
    single() { .SampleClass() } 
}

As you can see it adds a . in front of the SampleClass which causes a syntax error.

Observation When I add an additional folder into the ../koin folder like ../koin/example/ in which I move the SampleClass, the Default.kt file gets properly generated.

Koin module and version:

arnaudgiuliani commented 5 months ago

fixed in #113