Does Kotlin Work With Jlink?

It has been confirmed that Kotlin supports Java 9 onwards, does that include support for jlink? How is Kotlin JVM generating a Java platform module? Trying to use jlink but can’t find the Java platform module for the Kotlin program, which is supposed to be generated (presumably by the Kotlin compiler?).

Using Kotlin v1.2.40, Gradle v4.7 (via Kotlin DSL), and JDK 10.0.0 (Zulu) from SDK Man.

1 Like

Kotlin doesn’t work with jlink at the moment because jlink requires all constituent modules to be explicit (to have module-info.class), and the standard Kotlin library is not yet an explicit module. Here’s the related issue:

Presumably a written Kotlin program has a module generated for it when the Kotlin compiler detects JDK 9 or higher is being used? Why is it possible for the Kotlin standard library to be listed as a requirement in yet there is no module for it?

This is not how modules work in Jigsaw (the Java 9 module system). You either provide an explicit module definition in the, in which case the artifact used on the module path would be loaded as an explicit module by the module system, or you don’t, in which case that artifact is loaded as an “automatic” module, which is sort of a middle ground between the beautiful and ordered world of explicit modules, and chaotic and unsafe world of unnamed modules (aka classpath). Both module types, explicit and automatic, can be used at runtime in a Java 9 application. However, unfortunately, jlink specifically cannot handle automatic modules.

Please refer to the Java 9 module system docs for more info on modules and how are they defined: Project Jigsaw (I especially recommend the State of the Module System document, although it’s slightly outdated).

Is there an alternative tool to jlink that creates something similar to a binary (which bundles the JRE and assets used by a program like configuration files, icons etc), which will work with Kotlin 1.2.x and JDK 9 or greater, that doesn’t have the Java platform module requirement?

Will the upcoming Kotlin 1.2.50 release allow Explicit modules to be created (for Kotlin programs and libraries)?