Skip to content

Koin compiler plugin is incompatible with Kotlin 2.4.0 #2431

Description

@ymontero-max

Describe the bug

After upgrading Kotlin from 2.3.21 to 2.4.0, the Android project no longer compiles when the Koin compiler Gradle plugin is applied. Compilation fails during Kotlin compiler plugin registration with a ClassCastException inside KoinPluginComponentRegistrar.

To Reproduce

Steps to reproduce the behavior:

  1. Use an Android project with Koin annotations and the Koin compiler Gradle plugin.
  2. Configure:
    • kotlin = "2.4.0"
    • koin = "4.2.1"
    • koinCompilerPlugin = "1.0.0"
  3. Apply the plugin:
plugins {
    alias(libs.plugins.koin.compiler)
}
  1. Run:
./gradlew :app:compileDebugKotlin
  1. See the compiler failure:
java.lang.ClassCastException:
org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrarAdapter$Companion
cannot be cast to
org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor

at org.koin.compiler.plugin.KoinPluginComponentRegistrar.registerExtensions(...)

Expected behavior

The project should compile successfully with Kotlin 2.4.0, or the plugin should clearly report that Kotlin 2.4.0 is not supported yet instead of failing with an internal compiler/plugin ClassCastException.

Koin module and version:

koin-android:4.2.1
koin-androidx-compose:4.2.1
koin-annotations:4.2.1
koin-compose-navigation3:4.2.1
io.insert-koin.compiler.plugin:1.0.0

Also tested:

io.insert-koin.compiler.plugin:1.0.0-RC2

Same ClassCastException.

Snippet or Sample project to help reproduce

Version catalog:

[versions]
kotlin = "2.4.0"
koin = "4.2.1"
koinPlugin = "1.0.0"

[libraries]
koin-android = { module = "io.insert-koin:koin-android", version.ref = "koin" }
koin-androidx-compose = { module = "io.insert-koin:koin-androidx-compose", version.ref = "koin" }
koin-annotations = { module = "io.insert-koin:koin-annotations", version.ref = "koin" }

[plugins]
koin-compiler = { id = "io.insert-koin.compiler.plugin", version.ref = "koinPlugin" }

Gradle plugin usage:

plugins {
    alias(libs.plugins.koin.compiler)
}

Koin compiler config:

koinCompiler {
    userLogs = false
    debugLogs = false
    compileSafety = true
    skipDefaultValues = true
    unsafeDslChecks = true
}

Minimal annotation usage:

@Module
@ComponentScan("com.example")
class AppModule

@Single
class ExampleRepository

@KoinViewModel
class ExampleViewModel(
    private val repository: ExampleRepository
) : ViewModel()

Application:

@KoinApplication
class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()

        startKoin<MyApplication> {
            androidContext(this@MyApplication)
        }
    }
}

Workaround:

Downgrading Kotlin back to 2.3.21 with io.insert-koin.compiler.plugin:1.0.0 makes the project compile again.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions