This message was deleted.
# community-support
s
This message was deleted.
r
I'm attempting to set up HotswapAgent, which requires ability to reload some internals, hence -add-opens, so I have:
Copy code
application {
    mainClass.set("ah.MainKt")

    tasks.named<JavaExec>("run") {
        doFirst {
            ...  

            if (hotswapAgentCore != null) {
                println("Monitoring ${project.buildDir.absolutePath}/classes/kotlin/jvm/main/ for changes!")
                jvmArgs(
                    "-javaagent:${hotswapAgentCore.absolutePath}=autoHotswap=true",
                    "--add-opens java.base/java.lang=ALL-UNNAMED",
                    "--add-opens java.base/jdk.internal.loader=ALL-UNNAMED",
                    "--add-opens java.base/java.io=ALL-UNNAMED",
                    "--add-opens java.desktop/java.beans=ALL-UNNAMED",
                    "--add-opens java.desktop/com.sun.beans=ALL-UNNAMED",
                    "--add-opens java.desktop/com.sun.beans.introspect=ALL-UNNAMED",
                    "--add-opens java.desktop/com.sun.beans.util=ALL-UNNAMED",
                    // TODO try using the non-deprecated alternative to buildDir (I couldn't figure out how to get a path from it in 60s so gave up)
                    "-Dhotswap.classes.dir=${project.buildDir.absolutePath}/classes/kotlin/jvm/main/"

                )
            } else {
                throw IllegalStateException("Hotswap Agent Core dependency not found in the 'implementation' configuration.")
            }
        }
when I run, I get:
Copy code
> Task :run FAILED
Monitoring /home/rfirmin/code/clients/lobster/build/classes/kotlin/jvm/main/ for changes!
Unrecognized option: --add-opens java.base/java.lang=ALL-UNNAMED
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':run'.
> Process 'command '/usr/lib/jvm/java-17-openjdk-amd64/bin/java'' finished with non-zero exit value 1
but this works:
Copy code
> /usr/lib/jvm/java-17-openjdk-amd64/bin/java --add-opens
Error: --add-opens requires modules to be specified
v
You pack two options into one
👆 1
Not
"--add-opens java.base/java.lang=ALL-UNNAMED",
, but
"--add-opens",  "java.base/java.lang=ALL-UNNAMED",
r
ahhhh. ok. let me try
v
Besides that, changing the configuration of the task in the execution phase (
doFirst { ... }
) is a very bad idea and with configuration cache even forbidden
r
oh weird, i don't know where i ended up with doFirst. splitting the args worked, and i moved everything out of doFirst also. thank you