kscripting / kscript

Scripting enhancements for Kotlin
MIT License
2.07k stars 124 forks source link

Does not work with Kotlin 1.9.0 #408

Closed dalewking closed 1 year ago

dalewking commented 1 year ago

Trying kscript for the first time and installed kotlin and kscript with sdkman on Mac and simple execution fails:

% kscript 'println("hello world")'
Exception in thread "main" java.lang.ClassNotFoundException: kscript.scriplet.Scriplet
        at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:587)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
        at Main_Scriplet$Companion.main(Main_Scriplet.kt:5)
        at Main_Scriplet.main(Main_Scriplet.kt)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.jetbrains.kotlin.runner.AbstractRunner.run(runners.kt:70)
        at org.jetbrains.kotlin.runner.Main.run(Main.kt:188)
        at org.jetbrains.kotlin.runner.Main.main(Main.kt:198)
[kscript] [ERROR] Execution of scriplet failed:
[kscript] [ERROR] Command     : 'bash -c /Users/dalewking/.sdkman/candidates/kotlin/1.8.20/bin/kotlin  -classpath '/Users/dalewking/Library/Caches/kscript/jar_7a6cdcc8b547b2bb2a0ad2ab4f24c291/scriplet.jar:/Users/dalewking/.sdkman/candidates/kotlin/1.8.20/lib/kotlin-script-runtime.jar' Main_Scriplet '
[kscript] [ERROR] Exit Code   : 1   
[kscript] [ERROR] 

Tried with Kotlin 1.9.0 and 1.8.20 since I thought new kotlin version may have been the issue

dalewking commented 1 year ago

I tried to re-invoke with -d argument to get more info and now it works

dalewking commented 1 year ago

Actually it may have been that I also tried a kscript -c to get it working

dalewking commented 1 year ago

OK the issue is that it isn't working with Kotlin 1.9. Switching to Kotlin 1.8.20 allows it to work, but it is necessary to clear the cache after switching versions.

cgruber commented 1 year ago

Same thing here. We just upgraded our cli tools to 1.9 and kscript dies on the same error.

aartiPl commented 1 year ago

I will have a look at it.

iamironz commented 1 year ago

Same here.

Exception in thread "main" java.lang.ClassNotFoundException: kscript.scriplet.Android_lint
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:476)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    at Main_Android_lint$Companion.main(Main_Android_lint.kt:5)
    at Main_Android_lint.main(Main_Android_lint.kt)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.jetbrains.kotlin.runner.AbstractRunner.run(runners.kt:70)
    at org.jetbrains.kotlin.runner.Main.run(Main.kt:188)
    at org.jetbrains.kotlin.runner.Main.main(Main.kt:198)

We've updated Kotlin version up to 1.9.0 on developer machines and all the scripts got broken, as a result, all local script calls crashed. Fortunately, on CI it still works as the Docker container has pinned runtime versions. If you need any help - don't hesitate to ask, as we are heavily relying on kscript in our project to reproduce CI steps locally we consider this issue critical.

aartiPl commented 1 year ago

I am working on this. The root cause seems to be that Kotlin 1.9 disallows .kts files in the source roots. Anyway, I recommend pinning the Kotlin version on CI/CD - fixing bugs quickly won't always be possible.

iamironz commented 1 year ago

Thank you. Very much appreciated your effort there.

aartiPl commented 1 year ago

I have just released kscript 4.2.3-RC.1 Please check if everything works as expected in your code - there are changes in the core engine of kscript, so I would like to ensure that nothing is broken after fixing the problem.

sdk install kscript 4.2.3-RC.1
aartiPl commented 1 year ago

@cgruber , @dalewking , @iamironz - can you confirm that the issue is fixed?

iamironz commented 1 year ago

Works fine for me, thank you so much!

aartiPl commented 1 year ago

The final resolution is even simpler, without changing much in the kscript core. I have just released kscript 4.2.3 with Kotlin 1.9.0 compatibility.