JUnit5 Debugging mit Eclipse und Gradle

Eclipse und Gradle

Leider ist das Debuggen bzw. die Anlage einer Debugkonfiguration in Eclipse nicht ganz so trivial, wenn man das Java Modulesystem verwendet und Gradle als Buildsystem einsetzt. Dann liegt die Verantwortung der Dependencies bei Gradle und das Buildship Plugin von Eclipse stellt diese dann in Eclipse zur Verfügung.

Fehlermeldung beim Start

Startet man eine neu angelegte Debugkonfiguration (im Buildpath von ist JUnit 5 nicht angelegt und braucht sie auch nicht), dann erhält man eine Could not run test Fehlermeldung auf der Konsole:

java.lang.IllegalAccessError: class org.junit.platform.launcher.core.LauncherFactory (in unnamed module @0x3f200884) cannot access class org.junit.platform.commons.util.Preconditions (in module org.junit.platform.commons) because module org.junit.platform.commons does not export org.junit.platform.commons.util to unnamed module @0x3f200884

JUnit5 anpassen

Der ist das die Packages org.junit.platform.commons.util und org.junit.platform.commons.logging die ALL-UNNAMED Packages exportieren. Daher muss in den Debugkonfiguration die folgenden VM Parameter anhängen, dann verschwinden die Start Fehlermeldungen unter Eclipse und das Programm kann debugged werden.

--add-exports org.junit.platform.commons/org.junit.platform.commons.util=ALL-UNNAMED --add-exports org.junit.platform.commons/org.junit.platform.commons.logging=ALL-UNNAMED

Nun lässt sich mit Klick auf Debug die Anwendung debuggen.