Hi. Is there any known workaround for <https://you...
# scripting
j
Hi. Is there any known workaround for https://youtrack.jetbrains.com/issue/KT-28475 ? I'd like to use some DB calls in my scripts, but when using JVM11, I end up with
% cat script/Environment.ws.kts
Copy code
println("sql:" + javax.sql.DataSource::class.java)
% kotlinc -Xadd-modules=java.sql -script script/Environment.ws.kts
Copy code
java.lang.NoClassDefFoundError: javax/sql/DataSource
        at Environment_ws.<init>(Environment.ws.kts:1)
i
What is the definition of the
.ws.kts
scripts and who controls it? If you can control it, and it is really about the parent classloader, then there is a property in the evaluation configuration for setting the base classloader.
j
they are meant for utility tasks (some devops scripting, provisioning, things like that), so yes, basically I'm in total control of creating and running them, but still, I'm not able to force them to properly load java.sql module from jvm11
i
I need some more time to investigate the problem. Will try to find time this week.
j
Steps to reproduce (brand new amazon linux vm):
Copy code
[ec2-user@ip-... ~]$ sudo amazon-linux-extras install java-openjdk11
[ec2-user@ip-... ~]$ curl -s "<https://get.sdkman.io>" | bash
[ec2-user@ip-... ~]$ source "/home/ec2-user/.sdkman/bin/sdkman-init.sh"
[ec2-user@ip-... ~]$ sdk install kotlin

[ec2-user@ip-... ~]$ kotlinc -Xadd-modules=java.sql
Welcome to Kotlin version 1.3.61 (JRE 11.0.5+10-LTS)
Type :help for help, :quit for quit
>>> println("sql:" + javax.sql.DataSource::class.java)
java.lang.NoClassDefFoundError: javax/sql/DataSource
Caused by: java.lang.ClassNotFoundException: javax.sql.DataSource
	at java.base/java.lang.ClassLoader.findClass(ClassLoader.java:718)
	at org.jetbrains.kotlin.cli.common.repl.ReplClassLoader.findClass(ReplClassLoader.java:44)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	at Line_0.<init>(Line_0.kts:1)
🙏 1
Funny thing, java.sql is read for sure, because if I specify something crazy, like
-Xadd-modules=java.sdafkjlhaslkh
, I'm getting
Copy code
>>> println("sql:" + javax.sql.DataSource::class.java)
error: module java.sdafkjlhaslkh cannot be found in the module graph
error: module java.sdafkjlhaslkh cannot be found in the module graph
java.lang.NoClassDefFoundError: javax/sql/DataSource
Caused by: java.lang.ClassNotFoundException: javax.sql.DataSource
	at java.base/java.lang.ClassLoader.findClass(ClassLoader.java:718)
	at org.jetbrains.kotlin.cli.common.repl.ReplClassLoader.findClass(ReplClassLoader.java:44)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	at Line_0.<init>(Line_0.kts:1)
i
I investigated it, the problem is (mostly) correctly described in the KT-28475: compiler uses modules properly, but evaluator use too restrictive base classloader. The fix seems quite simple, so it will land on master relatively soon. But I'm affraid that it will only be released in the next cycle, it is too late for the upcoming 1.3.7x.
As of the workaround - I can only suggest to write your own host, with the new scripting API it could be done in a few lines of code.
j
👍 Thanks a lot!