Hi. Just started playing with kotlin scripting, go...
# scripting
Hi. Just started playing with kotlin scripting, got my first script up and running (jdk 11) simply by calling rwxr--r-- file ./dbtest.main.kts, that starts with shebang like
Copy code
#!/usr/bin/env kotlinc -Xadd-modules=java.sql -script

import java.sql.DriverManager

... actual code
now the problem is, that I cannot use
AutoCloseable.use { .... }
extension function, because it's not in common/jvm stdlib. How can I force kotlinc to use -jdk8 stdlib?
It seems that you'll need to add
into the classpath manually (via the
in the hashbang line)
thanks. tried it, and indeed it worked (but required stdlib-jdk7 - took me some time to figure t out 🙂 ) even better idea was to change DependsOn to
Copy code
@file:DependsOn("mysql:mysql-connector-java:8.0.19", "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.0")
as it uses indirect dependencies as well. Good enough for PoC. The problem is that I needed to specify 1.4.0 inside the script now and I'd prefer not to, as running on 1.4.1 sometime in future will download 1.4.0 instead of using local libs.
Yep, this is an obvious defficiency of the cli/scripting compiler, it should of course load the appropriate stdlib automatically. The same problem will arise if you'll compile regular sources with
. It would be nice if you'll create an issue on youtrack about it.