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:
- Use an Android project with Koin annotations and the Koin compiler Gradle plugin.
- Configure:
kotlin = "2.4.0"
koin = "4.2.1"
koinCompilerPlugin = "1.0.0"
- Apply the plugin:
plugins {
alias(libs.plugins.koin.compiler)
}
- Run:
./gradlew :app:compileDebugKotlin
- 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.
Describe the bug
After upgrading Kotlin from
2.3.21to2.4.0, the Android project no longer compiles when the Koin compiler Gradle plugin is applied. Compilation fails during Kotlin compiler plugin registration with aClassCastExceptioninsideKoinPluginComponentRegistrar.To Reproduce
Steps to reproduce the behavior:
kotlin = "2.4.0"koin = "4.2.1"koinCompilerPlugin = "1.0.0"plugins { alias(libs.plugins.koin.compiler) }Expected behavior
The project should compile successfully with Kotlin
2.4.0, or the plugin should clearly report that Kotlin2.4.0is not supported yet instead of failing with an internal compiler/pluginClassCastException.Koin module and version:
Also tested:
Same
ClassCastException.Snippet or Sample project to help reproduce
Version catalog:
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:
Application:
Workaround:
Downgrading Kotlin back to
2.3.21withio.insert-koin.compiler.plugin:1.0.0makes the project compile again.