Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Kotlin support Java 11?

Tags:

jvm

gradle

kotlin

I am trying to use Kotlin V1.2.70, Gradle V4.10.1 and Java 11. When compiling the project using gradle, an error saying "Unknown JVM Target Version: 11. Supported versions: 1.6, 1.8".

Does the Kotlin compiler supports Java 11 (produces code compatible with Java 11 JVM)? If so, how to configure that with gradle?

like image 872
dharanikesav Avatar asked Oct 19 '18 08:10

dharanikesav


People also ask

Does Kotlin work with Java 11?

Yes. Kotlin is supported as a first-class language on Android.

Does Kotlin support Java 14?

hadrianectorsm: Do you know if kotlin is already supported by java 14 ? Yes, it is. You can use 13 on compiler without any issue.

Does Kotlin support Java 17?

Kotlin 1.6. 0 supports JDK versions from JDK 1.6 through 17 (the latest released version at the moment).

Does Kotlin support Java 16?

The JDK 16 release includes plans to stabilize a new Java class type called record. To provide all the benefits of Kotlin and maintain its interoperability with Java, Kotlin is introducing experimental record class support.


2 Answers

The Kotlin compiler supports the JVM 9, 10, 11, and 12 bytecode versions as target since Kotlin 1.3.30 (changelog).

Prior to 1.3.30, only JVM 1.6 and 1.8 bytecode versions were supported as targets. Since you used 1.2.70, specifying JVM 11 bytecode as target led to the error you mentioned.

There are two solutions:

  • Specify 1.8 as JVM target bytecode version. As @yole said in his answer, this is fully compatible with JVM 11. In fact, as mentioned in the changelog of Kotlin 1.3.30, newer JVM target bytecode versions currently don't add any bytecode optimizations beyond the ones supported in 1.8, so it really doesn't make any difference for now anyway.

  • Upgrade to Kotlin 1.3.30 (or newer), then you can keep 11 as the JVM bytecode target value. The advantage is that you will automatically benefit from additional bytecode optimizations in future versions of the Kotlin compiler.

like image 132
Malte Skoruppa Avatar answered Sep 20 '22 12:09

Malte Skoruppa


The bytecode generated by the Kotlin compiler, when the target version is set to either 1.6 or 1.8, is fully compatible with JVM 11.

like image 38
yole Avatar answered Sep 18 '22 12:09

yole