{"record":{"id":"51978e4577f1bbc4","repo":"spring-projects/spring-boot","slug":"unable-to-find-s-dependency-please-ensure-juni","errorCode":null,"errorMessage":"Unable to find '%s' dependency. Please ensure JUnit is correctly configured.","messagePattern":"Unable to find '(.+?)' dependency\\. Please ensure JUnit is correctly configured\\.","errorType":"exception","errorClass":"MojoExecutionException","httpStatus":null,"severity":"error","filePath":"build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ProcessTestAotMojo.java","lineNumber":183,"sourceCode":"\tprivate URL[] addJUnitPlatformLauncher(URL[] classPath) throws Exception {\n\t\tString version = getJUnitPlatformVersion();\n\t\tDefaultArtifactHandler handler = new DefaultArtifactHandler(\"jar\");\n\t\thandler.setIncludesDependencies(true);\n\t\tSet<Artifact> artifacts = resolveArtifact(new DefaultArtifact(JUNIT_PLATFORM_GROUP_ID,\n\t\t\t\tJUNIT_PLATFORM_LAUNCHER_ARTIFACT_ID, version, null, \"jar\", null, handler));\n\t\tSet<URL> fullClassPath = new LinkedHashSet<>(Arrays.asList(classPath));\n\t\tfor (Artifact artifact : artifacts) {\n\t\t\tfullClassPath.add(artifact.getFile().toURI().toURL());\n\t\t}\n\t\treturn fullClassPath.toArray(URL[]::new);\n\t}\n\n\tprivate String getJUnitPlatformVersion() throws MojoExecutionException {\n\t\tString id = JUNIT_PLATFORM_GROUP_ID + \":\" + JUNIT_PLATFORM_COMMONS_ARTIFACT_ID;\n\t\tArtifact platformCommonsArtifact = this.project.getArtifactMap().get(id);\n\t\tString version = (platformCommonsArtifact != null) ? platformCommonsArtifact.getBaseVersion() : null;\n\t\tif (version == null) {\n\t\t\tthrow new MojoExecutionException(\n\t\t\t\t\t\"Unable to find '%s' dependency. Please ensure JUnit is correctly configured.\".formatted(id));\n\t\t}\n\t\treturn version;\n\t}\n\n\tprivate Set<Artifact> resolveArtifact(Artifact artifact) throws Exception {\n\t\tCollectRequest collectRequest = new CollectRequest();\n\t\tcollectRequest.setRoot(RepositoryUtils.toDependency(artifact, null));\n\t\tcollectRequest.setRepositories(this.project.getRemotePluginRepositories());\n\t\tDependencyRequest request = new DependencyRequest();\n\t\trequest.setCollectRequest(collectRequest);\n\t\trequest.setFilter(DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME));\n\t\tDependencyResult dependencyResult = this.repositorySystem\n\t\t\t.resolveDependencies(getSession().getRepositorySession(), request);\n\t\treturn dependencyResult.getArtifactResults()\n\t\t\t.stream()\n\t\t\t.map(ArtifactResult::getArtifact)\n\t\t\t.map(RepositoryUtils::toArtifact)","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/spring-projects/spring-boot/blob/270dfe353fb830fd69b823a8a859287ff103854b/build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ProcessTestAotMojo.java#L165-L201","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// 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>\n// after:  <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency>","handlingStrategy":"validation","validationCode":"// Pre-flight: assert junit-platform-commons is on the test classpath:\nString id = \"org.junit.platform:junit-platform-commons\";\nif (!project.getArtifactMap().containsKey(id)\n    || project.getArtifactMap().get(id).getBaseVersion() == null) {\n    throw new IllegalStateException(\"Add junit-platform-launcher/junit-jupiter to test deps\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    // invoke process-test-aot\n} catch (MojoExecutionException ex) {\n    if (ex.getMessage().startsWith(\"Unable to find 'org.junit.platform:junit-platform-commons'\")) {\n        // add JUnit Platform deps and retry\n    }\n    throw ex;\n}","preventionTips":["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."],"tags":["spring-boot","maven-plugin","aot","junit","dependencies"],"backgroundTag":null,"analyzedSha":"270dfe353fb830fd69b823a8a859287ff103854b","analyzedAt":"2026-08-11T19:42:06.541Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}