Skip to content

Spring Boot 3 – java.lang.ClassNotFoundException: org.junit.jupiter.api.io.CleanupMode

Error –

Caused by: java.lang.NoClassDefFoundError: org/junit/jupiter/api/io/CleanupMode
at org.junit.jupiter.engine.JupiterTestEngine.discover(JupiterTestEngine.java:66)
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverEngineRoot(EngineDiscoveryOrchestrator.java:152)
… 13 more
Caused by: java.lang.ClassNotFoundException: org.junit.jupiter.api.io.CleanupMode
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
… 15 more

Environment –

  • Spring Boot version 3 and above
  • Java version 17 and above
  • Junit 5

Root cause –

You may encounter this issue after upgrading from Spring Boot 2 to Spring Boot 3 with Junit 5. It is happening because any other library in your application is actually bringing an older version of junit-jupiter-api which is not compatible with latest Spring Boot.

Another possible root cause could be version difference between junit-jupiter-engine dependency and junit-jupiter-api dependency.

Solution –

Check you have below two dependencies in your application’ pom.xml having same version (version must be greater than 5.9.0 so that it is compatible with Spring Boot 3)

<dependency>
 <groupId>org.junit.jupiter</groupId>
 <artifactId>junit-jupiter-engine</artifactId> 
 <version>5.10.1</version> 
 <scope>test</scope> 
</dependency> 

<dependency> 
 <groupId>org.junit.jupiter</groupId> 
 <artifactId>junit-jupiter-api</artifactId> 
 <version>5.10.1</version> 
 <scope>test</scope>
</dependency>

Do you have another solution?

The solution provided above is based on the scenario our one of the developers/contributors faced. If you faced the same issue and found any other root cause then please share your solution in the comment section below. We will add the solution in this article.

1 thought on “Spring Boot 3 – java.lang.ClassNotFoundException: org.junit.jupiter.api.io.CleanupMode”

Leave a Reply

Your email address will not be published. Required fields are marked *