sbt / sbt-native-packager

sbt Native Packager
https://sbt-native-packager.readthedocs.io/en/stable/
BSD 2-Clause "Simplified" License
1.6k stars 439 forks source link

Cannot set --add-opens jvm setting #1604

Open Matzz opened 5 months ago

Matzz commented 5 months ago

Expected behaviour

I need to set --add-opens=java.base/sun.nio.ch=ALL-UNNAMED for my application.

Actual behaviour

When I set javaOptions += "-J--add-opensss=java.base/sun.nio.ch=ALL-UNNAMED" it fails with Unrecognized option: -J--add-opensss=java.base/sun.nio.ch=ALL-UNNAMED during the tests. Setting javaOptions += "--add-opens=java.base/sun.nio.ch=ALL-UNNAMED" does not fail but app fails with java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.util.Set sun.nio.ch.SelectorImpl.selectedKeys accessible: module java.base does not \"opens sun.nio.ch\" .... So ut seems that --add-opens was not applied to jvm configuration.

Information

jtjeferreira commented 4 months ago

You need to set Universal / javaOptions += "-J--add-opensss=java.base/sun.nio.ch=ALL-UNNAMED"

rkovalik-raft commented 2 months ago

I had trouble with this too. I tried all sorts of formatting for the strings with javaOptions and when it didn't throw formatting errors, it never seemed to use the java options I added.

I finally got it working by setting the JDK_JAVA_OPTIONS env variable in the project settings in build.sbt:

.settings(
    envVars ++= Map("JDK_JAVA_OPTIONS" -> "--add-opens=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED ")
)
dwickern commented 2 months ago

Try these settings:

javaOptions += "--add-opens=java.base/sun.nio.ch=ALL-UNNAMED"

// fork tests in order to pick up javaOptions when running tests
Test / fork := true

// these will be added to conf/application.ini and picked up by the script
Universal / javaOptions += "-J--add-opens=java.base/sun.nio.ch=ALL-UNNAMED"