spring-projects/spring-boot · error · MojoExecutionException
Unable to find ' ' dependency. Please ensure JUnit is…
Error message
Unable to find '%s' dependency. Please ensure JUnit is correctly configured.
What it means
MojoExecutionException thrown by ProcessTestAotMojo.getJUnitPlatformVersion when junit-platform-commons (group:org.junit.platform, artifact:junit-platform-commons) is absent from the resolved project artifact map. The AOT test processing fork requires the JUnit Platform version to construct the correct launcher classpath, so a missing dependency is fatal.
Solutions
- Add JUnit Platform dependencies: junit-platform-launcher and junit-jupiter (or include spring-boot-starter-test).
- Run `mvn dependency:tree -Dscope=test` and confirm org.junit.platform:junit-platform-commons resolves.
- Remove any <exclusions> on spring-boot-starter-test that strip junit-platform.
- If using a custom test runner, ensure junit-platform-commons is at least a transitive test dependency.
Example fix
// before: <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope><exclusions><exclusion><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter</artifactId></exclusion></exclusions></dependency> // after: <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency>
Defensive patterns
Strategy: validation
Validate before calling
// Pre-flight: assert junit-platform-commons is on the test classpath:
String id = "org.junit.platform:junit-platform-commons";
if (!project.getArtifactMap().containsKey(id)
|| project.getArtifactMap().get(id).getBaseVersion() == null) {
throw new IllegalStateException("Add junit-platform-launcher/junit-jupiter to test deps");
} Try / catch
try {
// invoke process-test-aot
} catch (MojoExecutionException ex) {
if (ex.getMessage().startsWith("Unable to find 'org.junit.platform:junit-platform-commons'")) {
// add JUnit Platform deps and retry
}
throw ex;
} Prevention
- Keep spring-boot-starter-test without stripping junit-platform exclusions.
- Verify `mvn dependency:tree -Dscope=test` lists junit-platform-commons.
- For projects still on JUnit 4, add junit-vintage-engine plus junit-platform-launcher.
When it happens
Trigger: Invoking spring-boot:process-test-aot when the project has no JUnit 5 (JUnit Platform) on the test classpath, or when junit-platform-commons has been excluded/transitive-resolution dropped it. platformCommonsArtifact == null OR its baseVersion is null.
Common situations: Project still on JUnit 4 without junit-platform-launcher/engine; spring-boot-starter-test excluded or stripped of junit-platform-commons; BOM override removing the platform; test scope mishandled so the artifact isn't in the artifact map.
Related errors
- Could not build classpath
- A jar or war file is required for building image
- Can't parse ' ' to instant
- Error packaging archive for image
- Failed to generate build-info.properties.
AI-assisted analysis of spring-projects/spring-boot@270dfe353f (2026-08-11).
Data as JSON: /api/errors/51978e4577f1bbc4.
Report an issue: GitHub.
Appendix: source
Thrown at build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ProcessTestAotMojo.java:183
private URL[] addJUnitPlatformLauncher(URL[] classPath) throws Exception {
String version = getJUnitPlatformVersion();
DefaultArtifactHandler handler = new DefaultArtifactHandler("jar");
handler.setIncludesDependencies(true);
Set<Artifact> artifacts = resolveArtifact(new DefaultArtifact(JUNIT_PLATFORM_GROUP_ID,
JUNIT_PLATFORM_LAUNCHER_ARTIFACT_ID, version, null, "jar", null, handler));
Set<URL> fullClassPath = new LinkedHashSet<>(Arrays.asList(classPath));
for (Artifact artifact : artifacts) {
fullClassPath.add(artifact.getFile().toURI().toURL());
}
return fullClassPath.toArray(URL[]::new);
}
private String getJUnitPlatformVersion() throws MojoExecutionException {
String id = JUNIT_PLATFORM_GROUP_ID + ":" + JUNIT_PLATFORM_COMMONS_ARTIFACT_ID;
Artifact platformCommonsArtifact = this.project.getArtifactMap().get(id);
String version = (platformCommonsArtifact != null) ? platformCommonsArtifact.getBaseVersion() : null;
if (version == null) {
throw new MojoExecutionException(
"Unable to find '%s' dependency. Please ensure JUnit is correctly configured.".formatted(id));
}
return version;
}
private Set<Artifact> resolveArtifact(Artifact artifact) throws Exception {
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(RepositoryUtils.toDependency(artifact, null));
collectRequest.setRepositories(this.project.getRemotePluginRepositories());
DependencyRequest request = new DependencyRequest();
request.setCollectRequest(collectRequest);
request.setFilter(DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME));
DependencyResult dependencyResult = this.repositorySystem
.resolveDependencies(getSession().getRepositorySession(), request);
return dependencyResult.getArtifactResults()
.stream()
.map(ArtifactResult::getArtifact)
.map(RepositoryUtils::toArtifact)View on GitHub (pinned to 270dfe353f)