Fixing the OutputDirectoryProvider Error
While running a Maven-based Java automation framework, if you faced this error: JUnit5 TestEngine Failed to Discover, then you are not alone. The error may appear while running mvn clean test or mvn clean install
The actual root cause may be:
OutputDirectoryProvider not available; probably due to unaligned versions of the junit-platform-engine and junit-platform-launcher jars on the classpath/module path.
This error indicates that different JUnit 5 components are using incompatible versions.
The Problem: JUnit Platform Version Mismatch
A typical Maven project may contain:
<dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <version>5.12.0</version> <scope>test</scope></dependency>
At the same time, another dependency or transitive dependency may introduce a different version of:
junit-platform-enginejunit-platform-launcherjunit-platform-commons
This can result in a mismatch during test discovery.
JUnit 5 is made up of multiple components:
JUnit Jupiter ↓JUnit Platform ↓Test Engine and Launcher
These components need to be aligned.
The Recommended Solution: Use the JUnit BOM
The cleanest solution is to use the JUnit Bill of Materials, also known as the JUnit BOM.
Add the BOM like below:
<dependencyManagement> <dependencies> <dependency> <groupId>org.junit</groupId> <artifactId>junit-bom</artifactId> <version>5.12.2</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies></dependencyManagement>
Then declare JUnit without specifying the version:
<dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <scope>test</scope></dependency>
The BOM manages compatible versions for the JUnit components.
Example Maven Configuration
A simplified configuration looks like this:
<properties> <junit.version>5.12.2</junit.version></properties><dependencyManagement> <dependencies> <dependency> <groupId>org.junit</groupId> <artifactId>junit-bom</artifactId> <version>${junit.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies></dependencyManagement><dependencies> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <scope>test</scope> </dependency></dependencies>
Important: JUnit Version Numbers
You may see versions such as:
JUnit Jupiter: 5.12.2JUnit Platform: 1.12.2
This is normal.
The version numbers are different, but they belong to the same JUnit release train.
The important thing is that the corresponding JUnit components are aligned.
How to Find Conflicting Dependencies
Run:
mvn dependency:tree -Dincludes=org.junit.jupiter,org.junit.platform
This displays the JUnit dependencies used by your project.
Look for multiple versions of:
org.junit.jupiterorg.junit.platform
For example, a problematic dependency tree may contain:
junit-platform-engine:1.12.2junit-platform-launcher:1.10.0
This kind of mismatch can cause:
OutputDirectoryProvider not available
and:
TestEngine with ID 'junit-jupiter' failed to discover tests
Do Not Solve the Problem by Removing Test Scope
A common reaction is to remove:
<scope>test</scope>
from the JUnit dependency.
However, this does not solve a JUnit Platform version mismatch.
JUnit should generally remain test-scoped:
<scope>test</scope>
This is the correct scope for test frameworks.
The Final Fix
After updating the Maven configuration, run:
mvn clean install
The JUnit BOM ensures that the Jupiter and Platform components are aligned.
Conclusion
The error:
TestEngine with ID 'junit-jupiter' failed to discover tests
does not always mean that your test code is incorrect.
If the root cause is:
OutputDirectoryProvider not available
check for incompatible versions of:
junit-platform-enginejunit-platform-launcher
Using the JUnit BOM is the cleanest way to keep JUnit dependencies aligned and prevent test discovery failures in Maven projects.
The key takeaway is simple:
Let the JUnit BOM manage compatible JUnit component versions instead of manually mixing individual JUnit Platform dependencies.
Related Articles
Cucumber JUnit5 Test Runner Migration
Discover more from Rotebit
Subscribe to get the latest posts sent to your email.
