spring-projects/spring-boot · error · MojoExecutionException

Unable to find '%s' dependency. Please ensure JUnit is corre

Error message

Unable to find '%s' dependency. Please ensure JUnit is correctly configured.

What it means

Thrown by ProcessTestAotMojo.getJUnitPlatformVersion as a MojoExecutionException when org.junit.platform:junit-platform-commons is not present in the project's resolved artifact map. The plugin needs the JUnit Platform Launcher to invoke the AOT processor on tests; it derives the launcher version from junit-platform-commons already on the test classpath. If JUnit Platform is not a dependency at all, the version cannot be inferred and the goal aborts.

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 5b2dbdbb8b)

Solutions

  1. Add org.junit.platform:junit-platform-launcher (test scope), or junit-jupiter which brings junit-platform-commons transitively.
  2. Ensure spring-boot-starter-test is a test dependency without excluding junit-jupiter.
  3. Confirm requiresDependencyResolution=TEST is honored — run mvn test-compile first so test deps resolve.
  4. If you genuinely have no JUnit tests, skip process-test-aot (e.g. -Dspring-boot.aot.skip or do not bind the goal).

Example fix

// before — JUnit excluded
<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 — keep JUnit, or add launcher explicitly
<dependency>
  <groupId>org.junit.platform</groupId>
  <artifactId>junit-platform-launcher</artifactId>
  <scope>test</scope>
</dependency>
Defensive patterns

Strategy: validation

Validate before calling

// Ensure junit-platform-commons is resolvable before process-test-aot
import org.apache.maven.project.MavenProject;

void ensureJUnitPlatform(MavenProject project) {
    String id = "org.junit.platform:junit-platform-commons";
    if (!project.getArtifactMap().containsKey(id)) {
        throw new IllegalStateException(
            "Add org.junit.platform:junit-platform-launcher (test) to run process-test-aot");
    }
}

Prevention

When it happens

Trigger: Running spring-boot:process-test-aot (or process-aot on tests) on a project that has no JUnit 5 (Jupiter) dependency; a project that uses TestNG or Spock only; a project whose spring-boot-starter-test was excluded or where junit-jupiter was excluded; running the goal before test dependencies are resolved.

Common situations: Excluding junit-jupiter from spring-boot-starter-test to use a different test framework; a multi-module reactor where the test-scoped JUnit deps were not yet resolved; an older project that still uses JUnit 4 only; custom test setup that omits junit-platform-commons.

Related errors


AI-assisted analysis of spring-projects/spring-boot@5b2dbdbb8b (2026-08-04). Data as JSON: /data/errors/51978e4577f1bbc4.json. Report an issue: GitHub.