GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Does not work with Kotlin 2.0.0 · Issue #421 · kscripting/kscript

Does not work with Kotlin 2.0.0 #421

New issue
Copy link
New issue
Copy link
Open
Open
Does not work with Kotlin 2.0.0#421
Copy link

Description

@MasWag
MasWag
opened on May 26, 2024
Issue body actions

It seems kscript does not work with Kotlin 2.0.0. What I observe is the same as #408:

$ 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:592)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
	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:183)
	at org.jetbrains.kotlin.runner.Main.main(Main.kt:193)
[kscript] [ERROR] Execution of scriplet failed:
[kscript] [ERROR] Command     : 'bash -c /opt/homebrew/Cellar/kotlin/2.0.0/libexec/bin/kotlin  -classpath '/Users/mwaga/Library/Caches/kscript/jar_7a6cdcc8b547b2bb2a0ad2ab4f24c291/scriplet.jar:/opt/homebrew/Cellar/kotlin/2.0.0/libexec/lib/kotlin-script-runtime.jar' Main_Scriplet '
[kscript] [ERROR] Exit Code   : 1   
[kscript] [ERROR] 

It works well with Kotlin 1.9.24 (after cache removal).

$ brew unlink kotlin && brew link [email protected]  && rm -rf ~/Library/Caches/kscript/ && kscript 'println("hello world")'
Unlinking /opt/homebrew/Cellar/kotlin/2.0.0... 6 symlinks removed.
Linking /opt/homebrew/Cellar/[email protected]/1.9.24... 6 symlinks created.
hello world
Reacted by Tokuhiro Matsuno, Vibin reddy, ThawZinToe, rnzbrngn, gokuma, Rime, theapache64, Franck Rasolo, Holger Brandl, Bruno Medeiros and 5 more

Activity

  1. NoUsernameProvided commented on Jun 7, 2024

    @NoUsernameProvided
    NoUsernameProvided
    on Jun 7, 2024
    More actions

    Same issue here.

  2. zorenkonte commented on Jun 12, 2024

    @zorenkonte
    zorenkonte
    on Jun 12, 2024
    More actions

    Got the same error

  3. aartiPl commented on Jun 12, 2024

    @aartiPl
    aartiPl
    on Jun 12, 2024
    Collaborator
    More actions

    I will try to solve it, although I don't have much time to invest. Contributions from anyone are more than welcome.

  4. aartiPl commented on Sep 11, 2024

    @aartiPl
    aartiPl
    on Sep 11, 2024
    Collaborator
    More actions

    I have investigated the issue. The problem with version 2.0 is that it completely changes how the scripts are executed. The current way of executing the script is by wrapping it with the following code:

    kscript/src/main/kotlin/io/github/kscripting/kscript/code/Templates.kt

    Line 48 in 6acd4e1

    fun createWrapperForScript(packageName: PackageName, className: String): String {

    But now, this method does not work anymore.

    I was also thinking about a more sophisticated way of rewriting the script so that it is put inside
    fun main() {}
    block. But it will only work for some cases - for example, enum class {} can not be defined in the function's local scope, so it will fail if you try to define an enum in your script.

    The only possible alternative I can see is to use the Kotlin script engine to implement the KScript engine. I have started the branch with those changes, but I don't have time to accomplish that work:

    kscript/src/main/kotlin/io/github/kscripting/kscript/KscriptHandler.kt

    Line 133 in 82af53b

    val kscriptHost = KscriptHost(config.osConfig.cacheDir)

    If anyone wants to take on this task, feel free to do so. I will accept the MRs.

  5. Dogacel commented on Oct 15, 2024

    @Dogacel
    Dogacel
    on Oct 15, 2024
    More actions

    @aartiPl if it doesn't work with kotlin 2.0+, is it possible to select which version of kotlin compiler to use? I tried using this for the first time and having the same error.

    Maybe we need an environment manager like jenv for kotlin.

  6. sergeych commented on Nov 12, 2024

    @sergeych
    sergeych
    on Nov 12, 2024
    More actions

    kscript is excellent and missing feature. it has to be upgraded to support koglin 2+, as many new code won't run with older versions, while kotlin's scripting itself is yet practically unusable. Thanks for incredible tool anyway... it was a great time using it.

    Reacted by Doğaç Eldenk and Luong Vo (Lucas)
  7. appreciated commented on Feb 5, 2025

    @appreciated
    appreciated
    on Feb 5, 2025
    More actions

    For others facing this issue, I faced a slightly different error message:

    Exception in thread "main" java.lang.ClassNotFoundException: kscript.scriplet.Client
    

    As a workaround, until there is kotlin 2.0 support, you can downgrade the kotlin version using sdkman:

    sdk install kotlin 1.9.24
    
  8. kamilmodest commented on Feb 12, 2025

    @kamilmodest
    kamilmodest
    on Feb 12, 2025
    More actions

    For me, it doesn't work with 1.9.24 either 🤔

    Macbooc M2 Pro (arm)

    Installed via

    ╰─>  sdk install kotlin 1.9.24
    ╰─>  sdk install kscript
    ╰─>  where kotlin
    /Users/k.babaev/.sdkman/candidates/kotlin/current/bin/kotlin
    ╰─>  where kscript
    /Users/k.babaev/.sdkman/candidates/kscript/current/bin/kscript
    

    Runs:

    ╰─>  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:592)
    	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
    	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:194)
    	at org.jetbrains.kotlin.runner.Main.main(Main.kt:204)
    [kscript] [ERROR] Execution of scriplet failed:
    [kscript] [ERROR] Command     : 'bash -c /Users/k.babaev/.sdkman/candidates/kotlin/1.9.24/bin/kotlin  -classpath '/Users/k.babaev/Library/Caches/kscript/jar_7a6cdcc8b547b2bb2a0ad2ab4f24c291/scriplet.jar:/Users/k.babaev/.sdkman/candidates/kotlin/1.9.24/lib/kotlin-script-runtime.jar' Main_Scriplet '
    [kscript] [ERROR] Exit Code   : 1
    [kscript] [ERROR]
    
    ╰─>  ll /Users/k.babaev/.sdkman/candidates/kscript
    Permissions Size User     Group Date Modified    Name
    drwxr-xr-x@    - k.babaev staff 2023-07-22 12:07  4.2.3
    lrwxr-xr-x@    - k.babaev staff 2025-02-12 18:56  current -> 4.2.3
    
    ╰─>  ll /Users/k.babaev/.sdkman/candidates/kotlin
    Permissions Size User     Group Date Modified    Name
    drwxr-xr-x@    - k.babaev staff 1980-02-01 00:00  1.9.24
    lrwxr-xr-x@    - k.babaev staff 2025-02-12 18:39  current -> 1.9.24
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.