Search code examples
javaintellij-ideakotlinjava-10

Kotlin with JDK 10


Recently I updated my JDK to JDK 10, and now I get configuration issue with Kotlin and I can't run my code. is this because of JDK 10 or it's because something else?

the hint I get from InteliJ while creating a Kotlin Project:

Configure Kotlin
        Added /Applications/IntelliJ IDEA CE.app/Contents/plugins/Kotlin/kotlinc/lib/kotlin-stdlib-jdk7.jar to library configuration
        Added /Applications/IntelliJ IDEA CE.app/Contents/plugins/Kotlin/kotlinc/lib/kotlin-stdlib-jdk7-sources.jar to library configuration
        Added /Applications/IntelliJ IDEA CE.app/Contents/plugins/Kotlin/kotlinc/lib/kotlin-stdlib-jdk8.jar to library configuration
        Added /Applications/IntelliJ IDEA CE.app/Contents/plugins/Kotlin/kotlinc/lib/kotlin-stdlib-jdk8-sources.jar to library configuration

Solution

  • At the time of writing (Sept. 2018) Kotlin's compiler does not support producing Java 9+ bytecode by default.

    The argument -jvm-target 9 (see KT-21959) should make the Kotlin compiler generate bytecode of version 53.

    Since Java 10 is bytecode version 54 (reference) - I'm not sure how this will work.

    Still:

    • You can compile to the JVM 8 bytecode which can be executed on JVM 9+ normally.

    • If you want to define modules (or use jlink that requires the entire program is modularized) you can write module-info.java files in Java today, and place in the same source root as Kotlin files.

      • The Kotlin compiler will correctly limit the accessibility of declarations in non-exported packages in dependent modules.
      • Currently, there are no plans to support module definitions in Kotlin.

    Other than that, most Java 9-11 language features (var, REPL, streams improvements, etc.) - already exist in Kotlin for a while, so the main immediate benefit of using Java 9-11 are using the JVM for the optimizations, or the module system / jlink (which you can use as descrbied above)