{"id":"abeeb0764079902a","repo":"spring-projects/spring-boot","slug":"unable-to-compile-generated-source","errorCode":null,"errorMessage":"Unable to compile generated source{}","messagePattern":"Unable to compile generated source(.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractAotMojo.java","lineNumber":180,"sourceCode":"\t\t\t\tString source = compilerConfiguration.getSourceMajorVersion();\n\t\t\t\tif (source != null) {\n\t\t\t\t\targs.add(\"--source\");\n\t\t\t\t\targs.add(source);\n\t\t\t\t}\n\t\t\t\tString target = compilerConfiguration.getTargetMajorVersion();\n\t\t\t\tif (target != null) {\n\t\t\t\t\targs.add(\"--target\");\n\t\t\t\t\targs.add(target);\n\t\t\t\t}\n\t\t\t}\n\t\t\targs.add(\"-parameters\");\n\t\t\targs.addAll(new RunArguments(this.compilerArguments).getArgs());\n\t\t\tIterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromPaths(sourceFiles);\n\t\t\tErrors errors = new Errors();\n\t\t\tCompilationTask task = compiler.getTask(null, fileManager, errors, args, null, compilationUnits);\n\t\t\tboolean result = task.call();\n\t\t\tif (!result || errors.hasReportedErrors()) {\n\t\t\t\tthrow new IllegalStateException(\"Unable to compile generated source\" + errors);\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected final URL[] getClassPath(File[] directories, ArtifactsFilter... artifactFilters)\n\t\t\tthrows MojoExecutionException {\n\t\tList<URL> urls = new ArrayList<>();\n\t\tArrays.stream(directories).map(this::toURL).forEach(urls::add);\n\t\turls.addAll(getDependencyURLs(artifactFilters));\n\t\treturn urls.toArray(URL[]::new);\n\t}\n\n\tprotected final void copyAll(Path from, Path to) throws IOException {\n\t\tif (!Files.exists(from)) {\n\t\t\treturn;\n\t\t}\n\t\tList<Path> files;\n\t\ttry (Stream<Path> pathStream = Files.walk(from)) {","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/spring-projects/spring-boot/blob/5b2dbdbb8be64415eb6552f81ff7c449c8d251e6/build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractAotMojo.java#L162-L198","documentation":"Thrown by AbstractAotMojo.compileSourceFiles() after the system JavaCompiler fails (task.call() returns false) or the Errors DiagnosticListener collected ERROR diagnostics. The generated AOT source files could not be compiled, and the collected compiler messages are appended. execute() wraps the IllegalStateException into a MojoExecutionException, so the user sees a Maven build failure.","triggerScenarios":"An AOT mojo (process-aot/test-aot, or the native-image mojos) calls compileSourceFiles() on the generated sources directory; javac reports errors (result==false or errors.hasReportedErrors()), so line 180 raises IllegalStateException(\"Unable to compile generated source\" + errors).","commonSituations":"Incompatible dependency versions fed to AOT; generated code references APIs not on the compiler classpath; JDK/toolchain mismatch (e.g., sources target newer language features than the build JDK); --release/source/target misconfiguration; a third-party library not AOT-friendly; corrupted generated sources from a prior run.","solutions":["Run with -X to see the full compiler diagnostics embedded in the exception message and fix the offending generated/source reference.","Clean previous AOT output: mvn clean to remove stale generated sources.","Align the build JDK/toolchain with spring-boot.aot.compilerArguments and the configured --release version.","Update or exclude dependencies that the AOT engine cannot process; verify the application compiles normally before enabling AOT/native.","If using a toolchain, confirm <jdk> toolchain is configured and points to a compatible JDK."],"exampleFix":"// before: build fails on AOT compile with mismatched release\n//   mvn -Pnative package\n//   -> \"Unable to compile generated source...\"\n// after: align toolchain + release, then clean\n// pom.xml\n//   <maven.compiler.release>21</maven.compiler.release>\n// shell:\n//   mvn clean package -Pnative\n","handlingStrategy":"try-catch","validationCode":"// Validate generated AOT sources compile cleanly before the native build\n// Run: mvn -Pnative compile process-aot first, then inspect target/spring-aot/main/sources\nval aotSources = java.io.File(\"target/spring-aot/main/sources\")\nif (aotSources.exists()) {\n    val ok = aotSources.walkTopDown().filter { it.isFile }.all { it.canRead() }\n    if (!ok) error(\"AOT sources incomplete; run mvn clean process-aot\")\n}\n","typeGuard":null,"tryCatchPattern":"try {\n    // invoke the AOT/native goal\n} catch (ex: org.apache.maven.plugin.MojoExecutionException) {\n    if (ex.cause is IllegalStateException && ex.message?.contains(\"Unable to compile generated source\") == true) {\n        project.logger.error(\"AOT compile failed; review -X output and align JDK/dependency versions.\")\n    }\n    throw ex\n}\n","preventionTips":["Ensure the application compiles and runs normally before enabling AOT/native.","Align the build JDK/toolchain with the configured --release version.","Run mvn clean after dependency or Spring Boot version bumps to regenerate AOT sources.","Keep dependencies on AOT-compatible versions; update or exclude problematic libs."],"tags":["maven","aot","native","compiler","java","build"],"analyzedSha":"5b2dbdbb8be64415eb6552f81ff7c449c8d251e6","analyzedAt":"2026-08-04T18:53:14.967Z","schemaVersion":2}