junit-team/junit5 · error · JUnitException
There should not be more than one ClasspathScanner…
Error message
There should not be more than one ClasspathScanner implementation present on the classpath but there were %d: %s
What it means
JUnitException thrown by ClasspathScannerLoader when java.util.ServiceLoader finds more than one ClasspathScanner implementation on the classpath. The SPI contract requires at most one provider; ambiguity is treated as a configuration error and the message lists both the count and the fully-qualified class names of all detected providers.
Solutions
- Inspect the error message - it lists the conflicting implementation class names
- Run mvn dependency:tree or gradle dependencies to find duplicate providers
- Exclude the duplicate junit-platform-commons artifact or the third-party scanner
- Keep a single ClasspathScanner provider on the test runtime classpath
Example fix
// build.gradle.kts - force a single version
configurations.all {
resolutionStrategy.eachDependency {
if (requested.group == "org.junit.platform") useVersion("1.13.3")
}
} Defensive patterns
Strategy: validation
Validate before calling
long count = ServiceLoader.load(ClasspathScanner.class).stream().count();
if (count > 1) {
// fail fast with a clear build error before tests run
} Prevention
- Run mvn dependency:tree or gradle dependencies before test runs to spot duplicate junit-platform-commons
- Avoid shading test framework artifacts into uber-jars
- Pin a single junit-bom version across the build
When it happens
Trigger: Two or more JARs each register a META-INF/services/org.junit.platform.commons.support.scanning.ClasspathScanner entry and both are visible to the context ClassLoader used by ServiceLoader.load.
Common situations: Duplicate or conflicting junit-platform-commons JARs pulled in transitively plus shading; a third-party test library that ships its own ClasspathScanner alongside the default; fat-jar/uber-jar assembly merging multiple service entries.
Related errors
- Cannot create Launcher for multiple engines with the same ID
- ArgumentConverter does not override the convert(Object…
- ArgumentsAggregator does not override the…
- Could not find any resource(s) with name
- Failed to find constructor for
AI-assisted analysis of junit-team/junit5@f070c699a0 (2026-08-11).
Data as JSON: /api/errors/2bde776ef72d0d0b.
Report an issue: GitHub.
Appendix: source
Thrown at junit-platform-commons/src/main/java/org/junit/platform/commons/util/ClasspathScannerLoader.java:36
import org.junit.platform.commons.support.scanning.ClasspathScanner;
/**
* @since 1.12
*/
class ClasspathScannerLoader {
static ClasspathScanner getInstance() {
ServiceLoader<ClasspathScanner> serviceLoader = ServiceLoader.load(ClasspathScanner.class,
ClassLoaderUtils.getDefaultClassLoader());
List<Provider<ClasspathScanner>> classpathScanners = serviceLoader.stream().toList();
if (classpathScanners.size() == 1) {
return classpathScanners.get(0).get();
}
if (classpathScanners.size() > 1) {
throw new JUnitException(
"There should not be more than one ClasspathScanner implementation present on the classpath but there were %d: %s".formatted(
classpathScanners.size(),
classpathScanners.stream().map(Provider::type).map(Class::getName).toList()));
}
return new DefaultClasspathScanner(ClassLoaderUtils::getDefaultClassLoader, ReflectionUtils::tryToLoadClass);
}
private ClasspathScannerLoader() {
}
}
View on GitHub (pinned to f070c699a0)