Java

Wie behebt man “DiscoverySelectors (in unnamed module) cannot access class Preconditions”?

Bei einem aktuellen modularen Java-Projekt bin ich auf folgendes Problem gestossen:

org.junit.platform.engine.discovery.DiscoverySelectors (in unnamed module @0x9d0b9d) cannot access class org.junit.platform.commons.util.Preconditions

Das führte dazu, dass die Unit-Tests nicht ausgeführt werden konnten und das Projekt auch nicht kompiliert werden konnte.

Die Fehlerbehebung ist relativ einfach. Bei der Konfiguration des Maven Surefire Plugins in der pom.xml des Projektes müssen zwei add-exports hinzugefügt werden:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M7</version>
    <configuration>
        <argLine>
            --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
        </argLine>
    </configuration>
</plugin>

René Pöpperl

Seit 2010 arbeite ich als Softwareentwickler. Mein hauptsächlichen Interessen liegen in gut durchdachtem UI-Design und hoher Code-Qualität.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Consent Management Platform von Real Cookie Banner