Running JUnits with JavaFX dependencies on Jenkins

176 Views Asked by At

I'm trying to setup pipeline on Jenkins for our JavaFX application. Everything works fine, but I have one problem by starting unit tests. Each test, which somehow uses JavaFX classes fails with following root cause:

Caused by: java.lang.IllegalAccessException: class net.bytebuddy.description.annotation.AnnotationDescription$ForLoadedAnnotation cannot access interface com.sun.javafx.beans.IDProperty (in module javafx.base) because module javafx.base does not export com.sun.javafx.beans to unnamed module @7ee955a8

I tried a following things:

  • setting env variable JAVA_OPTS
JAVA_OPTS=--module-path /path/to/javafx --add-modules javafx.controls,javafx.base
  • adding compiler options in gradle
tasks.withType(Test).configureEach {
    doFirst {
        options.compilerArgs += [
                '--module-path', '/path/to/javafx',
                '--add-modules', 'javafx.controls,javafx.base',
        ]
        classpath = files()
    }
}

but nothing changed. I'm using the OpenJDK compiled by Azul. I took the version with JavaFX (JDKFX) but I'm not able to make this tests running (tests without any references to JavaFX are running fine). I'm also able to compile the application. Do you have any sugestions?

1

There are 1 best solutions below

0
On

The problem was, like mentioned in comments, that it should not be added to the compilerArgs but to the runtime and additionally I placed it in wrong build.gradle file. The final configuration which solved all problems was to add following to the main build.gradle file:

allprojects {
  tasks.withType(Test).configureEach {
    jvmArgs += [
       '--add-modules', 'javafx.controls,javafx.base,javafx.graphics',
       '--add-opens', 'javafx.graphics/com.sun.javafx.application=ALL-UNNAMED',
       '--add-opens', 'javafx.base/com.sun.javafx.beans=ALL-UNNAMED',
    ]
  }
}