Skip to content

Please document how to add modules #340

Description

@DanySK

Hi, after lurking the old issues and trying several options, I still could not find how to add modules.
I see that the issues there and under Kotlin are now solved, but I can find no documentation nor working examples.
Could you document how to do so?

e.g., I expected:

@file:KotlinOpts("-J'--add-modules java.scripting'")
println(ScriptEngineManager())

to work, but it does not.

Activity

  1. holgerbrandl commented on Apr 19, 2022

    @holgerbrandl
    Collaborator

    The pure kotlin way is

    kotlin -howtorun script -J'--add-modules' -J'java.scripting' my_script.kts
    

    with my_script.kts being

    import javax.script.ScriptEngineManager
    
    println(ScriptEngineManager())

    Using kscript this should translate to (see https://discuss.gradle.org/t/gradle-does-not-honor-add-modules-jvm-argument-in-jdk9/20403)

    @file:KotlinOpts("-J'--add-modules' -J'java.scripting'")
    //@file:CompilerOpts("-J'--add-modules' -J'java.scripting'")
    
    import javax.script.ScriptEngineManager
    
    println(ScriptEngineManager())
    

    but this fails with Caused by: java.lang.ClassNotFoundException: javax.script.ScriptEngineManager. I don't know why, but given the history, I'd suspect the kotlin scripting classloader to not handle modules correctly. But this is just a weak guess.

    Sorry for the inconvenience.

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