InsertKoinIO / koin

Koin - a pragmatic lightweight dependency injection framework for Kotlin & Kotlin Multiplatform
https://insert-koin.io
Apache License 2.0
9.08k stars 719 forks source link

Koin BOM doesn't work for iOS targets #1721

Closed headsvk closed 7 months ago

headsvk commented 11 months ago

Describe the bug Hi. I tried to use the new Koin BOM but it doesn't work with Kotlin Multiplatform's iOS targets. Is that a limitation of Gradle/Kotlin Multiplatform?

To Reproduce Steps to reproduce the behavior:

  1. Add io.insert-koin:koin-bom:3.5.1 and io.insert-koin:koin-core dependencies to commonMain
  2. Sync project
  3. Results in errors
    :shared:iosMain: Could not resolve io.insert-koin:koin-bom:3.5.1
    :shared:iosMain: Could not find io.insert-koin:koin-core:.
    :shared:iosTest: Could not resolve io.insert-koin:koin-bom:3.5.1
    :shared:iosTest: Could not find io.insert-koin:koin-core:.

Expected behavior iOS targets can resolve the BOM version

Koin module and version: koin-bom:3.5.1 kotlin:1.9.20

cpaleop commented 10 months ago

It might be related to https://youtrack.jetbrains.com/issue/KT-58759 but it's highly unlikely since you should be seeing a different error

arnaudgiuliani commented 9 months ago

Without BOM is it working well?

headsvk commented 9 months ago

Yes it does

arnaudgiuliani commented 9 months ago

how do you declare your gradle config?

headsvk commented 9 months ago

I tried various things but I expect this to work:

    sourceSets {
        // Common
        val commonMain by getting {
            dependencies {
                api("io.insert-koin:koin-bom:3.5.1")
                api("io.insert-koin:koin-core")
            }
        }
     }
arnaudgiuliani commented 9 months ago

for bom you need to use platform keyword, like: platform api(...)

darronschall commented 8 months ago

I was running into this issue as well when adding Koin to a new KMP project that I had just created via the create project wizard.

Following the "version catalogs" setup via https://insert-koin.io/docs/setup/koin, I had:

// shared/build.gradle.kts
sourceSets {
        commonMain.dependencies {
            implementation(libs.koin.bom)
            implementation(libs.koin.core)
        }
}

This caused sync errors like the original author reported. The problem went away after using platform per the suggestion above:

sourceSets {
        commonMain.dependencies {
            implementation(project.dependencies.platform(libs.koin.bom))
            implementation(libs.koin.core)
        }
}

It might be worth changing the docs at https://github.com/InsertKoinIO/koin/blob/main/docs/setup/koin.md?plain=1#L54 to implementation(project.dependencies.platform(libs.koin.bom)) to make this explicit? I submitted https://github.com/InsertKoinIO/koin/pull/1822 to make that explicit.

arnaudgiuliani commented 7 months ago

Thank for your feedback. It's pushed online 👍