Djuro
01/17/2024, 8:45 AMkotlin-gradle-plugin
I am developing a library that uses kotlin-gradle-plugin
and in there I use toolchains like so:
kotlinExtension.jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(8))
}
kotlinOptions.jvmTarget = "1.8"
kotlin gradle plugin version is 1.8.10
Also if it is maybe relevant, I have an Android project and there android kotlin is applied like so
id("org.jetbrains.kotlin.android") version "1.8.10" apply false
When I publish my library and utilize it in the client application, I get Kotlin incompability issues
.gradle/caches/........ -> Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
Why would this matter? Why would Kotlin version used in the library matter, isn't it just compiled to java 8 binary in this case?
In the client app (I didn't work on it and am not allowed to change it)
I can see some legacy code like
id("org.jetbrains.kotlin.android") version "1.6.21" apply false
I just want the library to be compatible with this client app without a need to change a lot of things in the client app.
In library development as far as I understood I should have all the libraries be up to date. Only target/source compatability should be lower in order to support more client apps.
I have been trying to fix this without success. The only way was updating the app to the newest versions and for some reason I don't understand it needs android compileOptions
updated to Java 17
I have been stuck on this for a couple of days now. Can someone tell me how to fix this or at least lead me to some useful resources?tapchicoma
01/17/2024, 9:18 AMMiguel Oliveira
01/17/2024, 9:50 AMTgo1014
01/17/2024, 9:56 AMDjuro
01/17/2024, 1:16 PMDjuro
01/18/2024, 12:59 PMkotlin {
compilerOptions {
freeCompilerArgs.add(libs.versions.jdkTarget.map { // <5>
"-Xjdk-release=${it.toJdkTarget()}"
})
}
}
Adding -Xjdk-release="1.8"
to compiler arguments of KotlinJvmCompilerOptions
(compilerOptions) causes an error
e: JDK_HOME path is not specified in compiler configuration
Do you maybe know why that happens.
Note: Works even if I don't specify this line but I am unsure why adding this would cause any issues. Do you maybe know?Miguel Oliveira
01/18/2024, 1:29 PMplastiv
03/22/2024, 3:07 PMplastiv
03/22/2024, 4:27 PMfreeCompilerArgs.add("-Xjdk-release=11")
freeCompilerArgs.add("-jdk-home=/Library/Java/JavaVirtualMachines/zulu-21.jdk/Contents/Home")
Then there is a message
> w: The '-jdk-home' option is ignored because '-no-jdk' is specified
I've noticied no-jdk is set by kotlin android plugin https://github.com/JetBrains/kotlin/blame/bfbd03d046b426abb34ca0bc9bf1d8f5ec466b38[…]otlin/org/jetbrains/kotlin/gradle/plugin/KotlinAndroidPlugin.kt
Is it intended? So -Xjdk-release
is not possible for android projects?plastiv
03/22/2024, 4:42 PM-Xjdk-release
for android projects unless you use old and outdated java to build desired api version for android projects 😭Djuro
03/22/2024, 7:04 PMmbonnin
05/05/2024, 2:17 PMI believe this is becausee: JDK_HOME path is not specified in compiler configuration
jdk-release
doesn’t make sense for Android (Android doesn’t use rt.jar
). There is a specific message for the Java compiler but looks like the error is less explicit for Kotlin. See:
• https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:[…]leUtils.kt;l=410;drc=d59e14a47b09934c8c510174fceab9a290fe072d
• https://issuetracker.google.com/issues/278800528