hey all, We are trying to override what version of...
# gradle
n
hey all, We are trying to override what version of the kotlin stdlib we are using, with
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.7.21")
in out common main and have this set in our
kotlin.stdlib.default.dependency=false
gradle.properties file but we still get this error
/Users/ntamez/git/NatoNathan/math-kmp/build/.transforms/7d524b6b24a9d3827991c9c6de7b0371/transformed/out/jars/classes.jar!/META-INF/math-kmp_debug.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.
we are using 1.9 kotlin plugin and have the
languageVersion
and
apiVersion
set to 1.7 via
compilerOptions
this is a sample project we made to test this
settings.gradle.kts.kt
s
Copy code
tasks.withType<KotlinJvmCompile>().configureEach {
    compilerOptions {
        apiVersion.set(KotlinVersion.KOTLIN_1_9)
        languageVersion.set(KotlinVersion.KOTLIN_1_9)
        progressiveMode.set(true)
    }
}
Not really an expert but this sticks out. Is this on purpose?
☝️ 1
n
yeah, that was, it’s a kmp project, and we wanted to use 1,9 stuff on iOS and JS but need to support older kotlin versions on android
but simply setting
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.7.21")
should force the use of the older stdlib according to the docs,
If you declare a standard library dependency explicitly (for example, if you need a different version), the Kotlin Gradle plugin won’t override it or add a second standard library.
https://kotlinlang.org/docs/gradle-configure-project.html#dependency-on-the-standard-library
m
but simply setting
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.7.21")
should force the use of the older stdlib according to the docs
This will depend on
kotlin-stdlib:1.7.21
but your own classes will still contain 1.9 Kotlin metadata
Kotlin metadata are (amongst other things) annotations that allows the Kotlin compiler to understand the Kotlin constructs (extension functions, properties, etc...). They are embedded in your lib bytecode and you need a compiler that has version
n-1
to understand metadata produced by
n
(on the JVM)
n
thanks, this works
Copy code
tasks.withType<KotlinJvmCompile>().configureEach {
    compilerOptions {
        apiVersion.set(KotlinVersion.KOTLIN_1_7)
        languageVersion.set(KotlinVersion.KOTLIN_1_7)
        progressiveMode.set(true)
    }
}
only problem now i have uncommented the tests, I get this error
/Users/ntamez/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-test-junit/1.9.0/f106f1676ea59098e42e209709064c6e45b2913e/kotlin-test-junit-1.9.0.jar!/META-INF/kotlin-test-junit.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.
do i need to explicitly version
implementation(kotlin("test"))
?
m
Yes, if you don't set the version, it's using the same as the Kotlin Gradle Plugin
n
cool, thanks
300 Views