Closed 4ig closed 1 year ago
What is the output of ./gradlew -v
? The error message looks like you are using jdk 8 to run Gradle. Setting the toolchain to 11 will only use JDK 11 for certain tasks but not for Gradle itself. So the solution would be to use JDK 11 or newer to run Gradle (this can usually be configured with the JAVA_HOME
environment variable) and then setting target and jvmToolchain to 8.
Thank you for your response!
The error message looks like you are using jdk 8 to run Gradle
That's correct. I tried using Java 8 as a default as well as updating jvmToolchain
to 8.
Executing ./gradlew -v
would give me JVM: 1.8.0_362 (Temurin 25.362-b09)
. I set kotlinOptions.jvmTarget = '1.8'
and jvmToolchain(8)
. All of these used together would give me the error from the first comment.
So the solution would be to use JDK 11 or newer to run Gradle (this can usually be configured with the JAVA_HOME environment variable) and then setting target and jvmToolchain to 8.
This worked perfectly. Thank you. I am wondering why I didn't try it earlier. Just to confirm, this will produce proper JVM 8 bytecode, right?
Just to confirm, this will produce proper JVM 8 bytecode, right?
The jvmToolchain(8)
will make it so that the JavaCompile and KotlinCompile tasks run with jdk 8 even though Gradle itself runs in a different jdk.
Thank you for implementing this plugin! I have an issue with the following use case. I am working on a Kotlin library that I want to function on Android as well. At the moment, it targets JVM 11 and it gets published without issues. But I need to target JVM 1.8 in order to work on Android. I have the following config now.
If I change 11 here to 8 I and run the build using JDK 8 installed I get the following error:
Here is my build.gradle configuration.
Do you know how I can overcome this issue?
I can also set the toolchain version to 11 and the target version to 1.8 separately and run the build using JDK 11, like this:
This way I would get the warning:
I am not sure if it would produce bytecode compatible with Java 8.