Kotlin – Does Kotlin support Java 11

gradlejvmkotlin

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?

Best Answer

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.