mnlaptev
mnlaptev

Reputation: 121

NoClassDefFoundError exception after updating to the latest maven-surefire-plugin and latest junit5

I've got the following issue while I've been trying to use latest version of the JUnit5 (5.10.3) and latest version of the maven-surefire-plugin (3.3.0).

Caused by: org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
org/apache/maven/surefire/report/RunModeSetter
java.lang.NoClassDefFoundError: org/apache/maven/surefire/report/RunModeSetter
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
    at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:113)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:385)
    at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
    at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:507)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:495)
Caused by: java.lang.ClassNotFoundException: org.apache.maven.surefire.report.RunModeSetter
    at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
        ... 17 more

I've followed most of the official instructions (both junit and maven surefire) but nothing seems helping in my case.

The only difference is that the issue disappear if I go back to maven-surefire-plugin with version 3.0.0-M3

Are there any ways to found is it something known and already in-fix or what would be done differently on my end? It is a bit confusing that according to the maven surefire documentation everything should work.

p.s. I'm using JUnit5 as a bom and tried different combination of corresponding dependencies, like both engine and api or just api p.p.s. As for the maven version:

$ mvn -version
Apache Maven 3.9.0 (9b58d2bad23a66be161c4664ef21ce219c2c8584)
Maven home: C:\Users\mlaptev\Downloads\apache-maven-3.9.0
Java version: 1.8.0_412, vendor: Temurin, runtime: C:\Program Files\Eclipse Adoptium\jdk-8.0.412.8-hotspot\jre
Default locale: en_GB, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

Upvotes: 0

Views: 1124

Answers (5)

Dmitry Tsigelnik
Dmitry Tsigelnik

Reputation: 1

In my case adding

<dependency>
     <groupId>org.apache.maven.surefire</groupId>
     <artifactId>common-java5</artifactId>
     <version>${maven-surefire-plugin.version}</version>
     <scope>test</scope>
  </dependency>

helped avoiding this error

Update: After some investigation I found out that this dependency was breaking Surefire classpath and I had to add an exclusion.


<dependency>
    <groupId>com.github.psambit9791</groupId>
    <artifactId>jdsp</artifactId>
    <version>3.0.0</version>
    <exclusions>
        <exclusion>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-surefire-provider</artifactId>
        </exclusion>
    </exclusions>
</dependency> 

Also raised this JIRA https://issues.apache.org/jira/projects/SUREFIRE/issues/SUREFIRE-2285

Upvotes: 0

Simon Logic
Simon Logic

Reputation: 418

In my case i had to remove junit-platform-surefire-provider:

<!--        <dependency>-->
<!--            <groupId>org.junit.platform</groupId>-->
<!--            <artifactId>junit-platform-surefire-provider</artifactId>-->
<!--            <version>1.3.2</version>-->
<!--            <scope>test</scope>-->
<!--        </dependency>-->

And exception 'Caused by: java.lang.ClassNotFoundException: org.apache.maven.surefire.report.RunModeSetter' has gone.

I tested combination of surefire 3.4.0 and junit jupiter 5.10.3.

Upvotes: 1

mnlaptev
mnlaptev

Reputation: 121

Actually, it seems gone with using surefire plugin version 3.4.0

Upvotes: 0

1. Update below POM Configuration in the "pom.xml"

    <dependencies>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.10.3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.10.3</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.3.0</version>
            <configuration>
                <useModulePath>false</useModulePath>
            </configuration>
        </plugin>
    </plugins>
</build>

2. then force update dependencies by using

mvn clean install -U

Upvotes: 0

Aditya Banerjee
Aditya Banerjee

Reputation: 1

Try updating your jdk to 17 or any latest version

Upvotes: 0

Related Questions