Does Kotlin support Java 11?
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?
Solution 1:
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.
Solution 2:
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.
Solution 3:
As of Kotlin 1.4, it supports Java 1.6
(default), 1.8
, 9
, 10
, 11
, 12
, 13
and 14
-jvm-target Specify the target version of the generated JVM bytecode. Possible values are 1.6, 1.8, 9, 10, 11, 12, 13 and 14. The default value is 1.6.
https://kotlinlang.org/docs/reference/compiler-reference.html#-jvm-target-version
Yes, it fully supports Java 11.