{"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/5b2dbdbb8be64415eb6552f81ff7c449c8d251e6/build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ProcessTestAotMojo.java#L165-L201","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add org.junit.platform:junit-platform-launcher (test scope), or junit-jupiter which brings junit-platform-commons transitively.","Ensure spring-boot-starter-test is a test dependency without excluding junit-jupiter.","Confirm requiresDependencyResolution=TEST is honored — run mvn test-compile first so test deps resolve.","If you genuinely have no JUnit tests, skip process-test-aot (e.g. -Dspring-boot.aot.skip or do not bind the goal)."],"exampleFix":"// before — JUnit excluded\n<dependency>\n  <groupId>org.springframework.boot</groupId>\n  <artifactId>spring-boot-starter-test</artifactId>\n  <scope>test</scope>\n  <exclusions>\n    <exclusion><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter</artifactId></exclusion>\n  </exclusions>\n</dependency>\n// after — keep JUnit, or add launcher explicitly\n<dependency>\n  <groupId>org.junit.platform</groupId>\n  <artifactId>junit-platform-launcher</artifactId>\n  <scope>test</scope>\n</dependency>","handlingStrategy":"validation","validationCode":"// Ensure junit-platform-commons is resolvable before process-test-aot\nimport org.apache.maven.project.MavenProject;\n\nvoid ensureJUnitPlatform(MavenProject project) {\n    String id = \"org.junit.platform:junit-platform-commons\";\n    if (!project.getArtifactMap().containsKey(id)) {\n        throw new IllegalStateException(\n            \"Add org.junit.platform:junit-platform-launcher (test) to run process-test-aot\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep JUnit Jupiter (or junit-platform-launcher) as a test dependency.","Avoid blanket exclusions of junit-jupiter from spring-boot-starter-test.","Run mvn test-compile before process-test-aot so test deps are resolved."],"tags":["maven","spring-boot","aot","junit","test","dependencies"],"analyzedSha":"5b2dbdbb8be64415eb6552f81ff7c449c8d251e6","analyzedAt":"2026-08-04T18:53:14.967Z","schemaVersion":2}