I'm working on a Java 11 application that uses the java module system. I need to use reflection to access an internal function of the JavaFX library. The java module containing that function doesn't export it, so I get the following error when I run the gradle build task:
import com.sun.javafx.tk.TKStage;
^
(package com.sun.javafx.tk is declared in module javafx.graphics, which does not export it to module com.sampleapp)
I believe that means I need to do --add-exports javafx.graphics/com.sun.javafx.tk=com.sampleapp, however, I'm not sure how to do this in gradle. I've tried adding it to the applicationDefaultJvmArgs, which didn't work.
application {
...
applicationDefaultJvmArgs = listOf(
"--add-exports javafx.graphics/com.sun.javafx.tk=com.sampleapp"
)
}
I've also tried adding it to gradle.properties.kts and it didn't work.
org.gradle.jvmargs = listOf(
"--add-exports javafx.graphics/com.sun.javafx.tk=com.sampleapp"
)
I was able to solve the issue by adding:
tasks.withType<JavaCompile> {
options.compilerArgs.addAll(arrayOf(
"--add-exports", "javafx.graphics/com.sun.javafx.tk=com.sampleapp"
))
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With