InsertKoinIO / koin

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

Koin 3.5 is not binary-compatible with 3.4 #1829

Closed gsprdev closed 3 months ago

gsprdev commented 3 months ago

Describe the bug

If a library is compiled using Koin 3.4, and an app using Koin 3.5 tries to use that library, a runtime exception can occur.

Koin 3.5 appears to be source-compatible with 3.4, but is not binary-compatible.

This appears to be because Koin 3.5 violates kotlinlang.org's "Don't add arguments to existing API functions" guideline for libraries

To Reproduce

  1. Declare a library with a dependency on Koin 3.4.2
  2. Define an entrypoint which uses the koinApplication { } API as instructed in insert-koin.io's "Context Isolation" documentation
  3. Define an app with a dependency on both the test library and Koin 3.5.3 (using BOM)
  4. Invoke the library's entrypoint in an app

An exception similar to the following will be produced:

No static method koinApplication(Lkotlin/jvm/functions/Function1;)Lorg/koin/core/KoinApplication; in class Lorg/koin/dsl/KoinApplicationKt; or its super classes (declaration of 'org.koin.dsl.KoinApplicationKt' appears in […])

Expected behavior Maven dependency resolution will select 3.5.3 over 3.4.2 because they are theoretically semver-compatible and 3.5.3 is higher. Library will continue to function as expected, with isolated context.

Koin module and version: koin-core:3.5.3

Snippet or Sample project to help reproduce ~No standalone set of projects created, but a PR will follow.~ https://github.com/gsprdev/koin1829

gsprdev commented 3 months ago

Repro example: https://github.com/gsprdev/koin1829

arnaudgiuliani commented 3 months ago

Thanks for the feedback. Seen your PR 👍