Hi folks! I’m updating a project of mine from Kotl...
# scripting
s
Hi folks! I’m updating a project of mine from Kotlin 1.4 to 1.8 that use Custom script definition. At the time I was using JDK 8 on my machine + on the server that was running the script compilation. My project does a FatJar(using Gradle Shadow Plugin) with the hole Kotlin Compiler + My Script Definition and while updating I encounter a issue that by testing I found out that there is a problem with JDK 11, 17, 19 (the have tested in this versions) but with JDK 8 compiles just fine. I think this is because of the Java Module System from 9+, anyone encounter this problem and find a way to keep using FatJar with newer versions of the JDK?
c
We encountered an issue with scripting and fat-jar when trying to update from Kotlin 1.8.10 -> 1.8.21, both on JDK 11:
Copy code
RuntimeException: Using JDK home inferred from java.home: /usr/lib/jvm/zulu11-ca-amd64
Using JVM IR backend
Using new faster version of JAR FS: it should make your build faster, but the new implementation is experimental
Loading modules: [<http://java.se|java.se>, com.azul.tooling, jdk.accessibility, jdk.attach, jdk.compiler, jdk.dynalink, jdk.httpserver, jdk.jartool, jdk.javadoc, jdk.jconsole, jdk.jdi, jdk.jfr, jdk.jshell, jdk.jsobject, jdk.management, jdk.management.jfr, jdk.naming.ldap, <http://jdk.net|jdk.net>, jdk.scripting.nashorn, jdk.sctp, jdk.security.auth, jdk.security.jgss, jdk.unsupported, jdk.unsupported.desktop, jdk.xml.dom, kotlin.stdlib, kotlin.script.runtime, kotlin.reflect, java.base, java.compiler, java.datatransfer, java.desktop, java.xml, java.instrument, java.logging, java.management, java.management.rmi, java.rmi, java.naming, java.net.http, java.prefs, java.scripting, java.security.jgss, java.security.sasl, java.sql, java.transaction.xa, java.sql.rowset, java.xml.crypto, jdk.internal.jvmstat, jdk.management.agent, jdk.jdwp.agent, jdk.internal.ed, jdk.internal.le, jdk.internal.opt]
Module kotlin.stdlib cannot be found in the module graph
Module kotlin.script.runtime cannot be found in the module graph
Does this look like the error you are getting @SrSouza? We have not found a fix as of yet.
s
Yes! Exactly like that!
c
There might something relevant in this thread.
e
@SrSouza we have the same issue too, you can search the error in channel, after a quick look into kotlin repo I'd tell that you are right and it is related to commit they did which relates to 9 modules (I think there is a function called 'isModularJava' somewhere if I remember correctly, you can look too). There is an open issue in tracker as well. I spoke to Illya and it seems like they are all I to K2 release now and don't have resources for investigating right now.
@SrSouza another point to mention I'm pretty sure that regression came with 1.8.20, so using 1.8.10 or below will play
Oh saw right now that Christian already mentioned it.
s
The way I’m currently handling here is using Maven Aether to download all dependencies at startup and adding to the classloader (URLClassloader). This way the class-module is kept and it is working with any JDK version.
e
No, no luck with 1.8.22
@SrSouza thanks for suggestion. I'm not sure we can adopt this approach due to specifics of our system, but we definitely will chek it
@SrSouza @Christian Nedregaard any luck/progress with sorting that one out?
@SrSouza @Christian Nedregaard the workaround we found is to include those dependencies in the project (in most cases they are already there) and use flags "-no-stdlib", "-no-reflect" in compiler options. The only issue with this one is that if we use this approach is that running code in Intellij will throw the same error, so additionally we had to add condition checking if run from the fatJar or from Intellij. (Can be done by checking classpath) There are another workaround in youtrack , did not check this one though
c
@Egor Thanks. Will look into this.
@Egor Ended up using the workaround from youtrack as it required only one line of setup code. Works like a charm with Kotlin 1.9 👍
e
👍 thanks @Christian Nedregaard, I tend to take that as well.