Closed mgroth0 closed 1 month ago
Hm, normally, 1.7.x versions shouldn't work with Kotlin 1.9 because the compiler should reject them (release notes explain why. Does Gradle uses 2.0.20 compiler to compile buildscript, but then Kotlin 1.9 to run? Why there are no compiler errors about Your current Kotlin version is 1.9.22, while kotlinx.serialization core runtime 1.7.2 requires at least Kotlin 2.0.0-RC1. Please update your Kotlin compiler and IDE plugin
?
Good question. But regardless of what gradle compiles buildscripts with, gradle plugins can compile with serialization 1.7.X and kotlin 2.0.20 and run fine on gradle 8.8 until serialization 1.7.2.
Minimal reproducer:
import kotlinx.serialization.serializerOrNull
buildscript {
dependencies {
classpath("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.2")
}
repositories {
mavenCentral()
}
}
@OptIn(kotlinx.serialization.InternalSerializationApi::class)
println(Float::class.serializerOrNull())
Does Gradle uses 2.0.20 compiler to compile buildscript, but then Kotlin 1.9 to run
I believe Gradle uses 1.9 to compile and forces 1.9 at runtime. Because there is n+1 forward compatibility, it compiles fine.
Why there are no compiler errors
Looks like the error is triggered from the serialization compiler plugin? It might not be always applied.
A very important thing to serialize is that in gradle buildSrc
is special, and classes added to the classpath there are added to a very high level class loader (thus can not be overridden/specified in the project itself). This basically creates a Kotlin plugin version conflict. There is a workaround, use includeBuild
instead and have that define a plugin (for the project) that is applied like a normal plugin. You can then build the plugin with gradle's Kotlin version, and then use it with a newer kotlin plugin version. See also: https://discuss.gradle.org/t/different-behaivor-between-buildsrc-and-include-build-build-logic/47705 and https://discuss.gradle.org/t/different-behaivor-between-buildsrc-and-include-build-build-logic/47705
same error
kotlin 2.0.10 kotlinx.serialization 1.7.1 or 1.7.2 ktor: 3.0.0-rc-1
I have the same problem: Your current Kotlin version is 1.9.0, while kotlinx.serialization core runtime 1.7.1 requires at least Kotlin 2.0.0-RC1. Please update your Kotlin compiler and IDE plugin.
I fixed it just by changing the version: org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0
Gradle ships with a specific Kotlin version, and Gradle version 8.8 is the newest gradle version that is verified compatible with kotlin 2.0.20. However, Gradle 8.8 itself in its buildscript and settings script runs Kotlin version
1.9.22
as can be seen by printingKotlinVersion.CURRENT
in a build.gradle.kts script.If a gradle plugin author tries to include serialization plugin 1.7.1, everything works fine. But upon upgrading to 1.7.2, we are immediately hit with a runtime error during a gradle build:
This error is unavoidable, as the serialization plugin attempts to load the new kotlin UUID class regardless of whether or not the consumer is trying to serialize or deserialize a UUID.
To Reproduce
Expected behavior
I think its ok for consumers of get a runtime error if they try to serialize or deserialize a kotlin.uuid.UUID in a gradle build. In that case, of course the UUID class will not be available. But for this whole library to fail seems unnecessary. Making the loading of the UUID class conditional on whether or not it is used would retain backwards compatibility in the library.