0

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?

michalp
  • 83
  • 5
  • Do you literally have `/path/to/javafx` in your command line switch? – jewelsea Dec 09 '22 at 20:25
  • Maybe provide a `module-info.java` so that you don’t need command line switches. – jewelsea Dec 09 '22 at 20:27
  • 1
    Your issue is a runtime issue, not a compiler issue, so compiler options are irrelevant to the issue. – jewelsea Dec 09 '22 at 20:29
  • [With maven, you don’t need test code in a module](https://stackoverflow.com/questions/46613214/java-9-maven-junit-does-test-code-need-module-info-java-of-its-own-and-wher), with gradle, I don’t know. – jewelsea Dec 09 '22 at 20:33
  • No, path is not original, but I'm using the correct path. But the point with runtime and compiler option is good. – michalp Dec 12 '22 at 08:32
  • As this issue occurs due to the use of `bytebuddy`, perhaps this is a duplicate of [Mockito can not mock Random in Java 17](https://stackoverflow.com/questions/70993863/mockito-can-not-mock-random-in-java-17), which produces a very similar error message. – jewelsea Dec 12 '22 at 09:33
  • It is always a good idea to provide full stack traces rather than snippets. You can always highlight the cause for emphasis separately if you want. – jewelsea Dec 12 '22 at 09:35
  • @jewelsea, but it's not general problem of mocking. On my computer everything is working fine. The problem I'm getting only on the CI. – michalp Dec 12 '22 at 12:12
  • Did you try running the CI tests with the argument recommended in the link and as suggested by the error message text you received? `--add-opens javafx.base/com.sun.javafx.beans=ALL-UNNAMED` – jewelsea Dec 12 '22 at 12:18

1 Answers1

0

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',
    ]
  }
}
michalp
  • 83
  • 5