0

In a non-modular app that uses ControlsFX's GridView (ControlsFX version = '11.1.1', JDK 17), if I run it in an Eclipse launch configuration with the VM arguments settings (in the (x)=Arguments tab) with the same --add-opens and --add-export arguments as shown in the code snippet below, the app runs just fine.

However, when I invoke gradle run from the Gradle Tasks view in Eclipse, with the following run block, the result is

java.lang.IllegalAccessError: 
    class org.controlsfx.control.spreadsheet.GridBase (in unnamed module @0x73a0cead) 
    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 @0x73a0cead

Here's the run block in build.gradle for the project.

run {
    jvmArgs
    '--add-opens=javafx.controls/javafx.scene.control.skin=org.controlsfx.controls \
        --add-opens=javafx.controls/javafx.scene.control.skin=ALL-UNNAMED \
        --add-exports=javafx.base/com.sun.javafx.event=org.controlsfx.controls \
        --add-exports=javafx.base/com.sun.javafx.event=ALL-UNNAMED \
        --add-exports=javafx.graphics/com.sun.javafx.scene=org.controlsfx.controls, \
        --add-exports=javafx.graphics/com.sun.javafx.scene.traversal=org.controlsfx.controls \
        --add-exports=javafx.graphics/com.sun.javafx.css=org.controlsfx.controls \
        --add-exports=javafx.graphics/com.sun.javafx.scene=org.controlsfx.controls \
        --add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=org.controlsfx.controls'
}

the app runs, but the FXML views that include a GridView are empty windows (as expected given the above error).

You can clearly see that the export of javafx.base/com.sun.javafx.event is specified in the run block. Yet the behavior of gradle run is different (failure) from that of the launch configuration (success).

Any thoughts on what is causing the failure would be greatly appreciated.

pfurbacher
  • 1,789
  • 3
  • 15
  • 23

1 Answers1

0

I finally settled on the following way to set the jvmArgs for the run task. Since I'm doing this in Eclipse (Spring Tool Suite, actually), the relevant contents of build.gradle are:

plugins {
    id 'java-library'
    id 'eclipse'
    id 'application'
} 

The application block is where one sets applicationDefaultJvmArgs (seems like a poor choice to use "Default" since these are custom settings!):

application {
    mainClass = ...
    applicationName = ... 
    applicationDefaultJvmArgs = jvmArgs
}

Gradle Application plugin documentation is here.

In my case, I set the jvmArgs value in the ext block. Note that I have to include a bunch of other add-export and add-opens because I use quite a few other controls from the ControlsFX project. See Using ControlsFX with JDK 9 and above for notes on individual controls.

ext {
    ...
    jvmArgs = [
        '--add-exports=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED',
        '--add-opens=javafx.controls/javafx.scene.control.skin=org.controlsfx.controls',
        '--add-opens=javafx.controls/javafx.scene.control.skin=ALL-UNNAMED',
        '--add-exports=javafx.base/com.sun.javafx.event=org.controlsfx.controls',
        '--add-exports=javafx.base/com.sun.javafx.event=ALL-UNNAMED',
        '--add-exports=javafx.graphics/com.sun.javafx.scene=org.controlsfx.controls,',
        '--add-exports=javafx.graphics/com.sun.javafx.scene.traversal=org.controlsfx.controls',
        '--add-exports=javafx.graphics/com.sun.javafx.css=org.controlsfx.controls',
        '--add-exports=javafx.graphics/com.sun.javafx.scene=org.controlsfx.controls',
        '--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=org.controlsfx.controls',
        '--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=ALL-UNNAMED' 
     ]
    ...
}

To use ControlsFX GridView in JavaFX 9+, add the following:

'--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=org.controlsfx.controls'
'--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=ALL-UNNAMED' 

which are the last two items in the jvmArgs list above.

There's a difference between setting these jvmArgs in an Eclipse launch configuration and executing the run task in Gradle: the launch configuration does not seem to require

--add-exports=javafx.controls/com.sun.javafx.scene.control.behavior=ALL-UNNAMED

That's where I was being thrown off.

Side-note: honestly, I don't know where I got the notion that the run block accepted a string for jvmArgs.

pfurbacher
  • 1,789
  • 3
  • 15
  • 23