Gradle run with `--add-exports`

感情迁移 提交于 2020-01-24 18:10:28

问题


I got a java.lang.IllegalAccessError because of using a com.sun.* class in Java >9. The solution to this is to add --add-exports=javafx.base/com.sun.javafx.event=org.controlsfx.controls. I'm not sure how to add this to my build.gradle, but I put

run {
    jvmArgs = ['--add-exports=javafx.base/com.sun.javafx.event=org.controlsfx.controls']
}

into it and it didn't help. This is pretty much the issue I have. The error message is:

java.lang.IllegalAccessError: class org.controlsfx.control.textfield.AutoCompletionBinding (in unnamed module @0x2d7444bc) cannot access class com.sun.javafx.event.EventHandlerManager (in module javafx.base) because module javafx.base does not export com.sun.javafx.event to unnamed module @0x2d7444bc
    at org.controlsfx.control.textfield.AutoCompletionBinding.<init>(AutoCompletionBinding.java:522) ~[controlsfx-11.0.0.jar:11.0.0]
    at impl.org.controlsfx.autocompletion.AutoCompletionTextFieldBinding.<init>(AutoCompletionTextFieldBinding.java:107) ~[controlsfx-11.0.0.jar:11.0.0]
    at org.controlsfx.control.textfield.TextFields.bindAutoCompletion(TextFields.java:151) ~[controlsfx-11.0.0.jar:11.0.0]
[…]
    at java.lang.Thread.run(Thread.java:835) [?:?]

回答1:


It looks like you don't have a modular project. There are two options to solve it:

  • Make a modular project

If you add a module-info descriptor, like:

module hellofx {
    requires javafx.controls;
    requires org.controlsfx.controls;

    exports org.openjfx;
}

(adding your modules there, of course), it will work with:

run {
    jvmArgs = ['--add-exports= \
                javafx.base/com.sun.javafx.event=org.controlsfx.controls']
}
  • Export to all modules

Since your project is not modular, it is part of the so called unnamed module. Therefore, you should use ALL-UNNAMED, so the package is exported to all the modules, including ControlsFX:

run {
    jvmArgs = ['--add-exports=javafx.base/com.sun.javafx.event=ALL-UNNAMED']
}


来源:https://stackoverflow.com/questions/58082298/gradle-run-with-add-exports

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!