{"record":{"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/270dfe353fb830fd69b823a8a859287ff103854b/build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractAotMojo.java#L162-L198","documentation":"Thrown by AbstractAotMojo after invoking the Java compiler on AOT-generated source files (via the JSR-199 CompilationTask). If task.call() returns false OR the Errors object has reported errors, an IllegalStateException is thrown with the full error dump appended. This means the ahead-of-time compilation of generated processing/source code (for native or AOT optimizations) failed with real compile errors.","triggerScenarios":"Running the Spring Boot Maven AOT mojo (e.g. process-aot, process-test-aot) or the native build Mojo, when the AOT processor generated source files that contain compilation errors — references to missing types, invalid generated code, incompatible classpath, or --release/--target mismatches. The generated sources are compiled with the project's compilerArguments.","commonSituations":"AOT processing generated code that references a type not on the compile classpath (e.g. a conditional bean whose generating context is missing a dependency). Using a --release or --target argument incompatible with the JDK. Conflicting versions of Spring dependencies causing generated hints to be wrong. Mixing GraalVM native-image with an app that uses unsupported reflection/proxies not captured by AOT hints. JDK version mismatch between the build JDK and target.","solutions":["Read the 'errors' text appended to the message — it contains the exact compiler diagnostics (file, line, error) for the generated sources; fix the root cause (missing dependency, version conflict).","Ensure all compile-scoped dependencies needed at AOT time are present and version-aligned with spring-boot/starter versions.","Check the -target/--release arguments and compilerArguments; align them with the running JDK version.","Run 'mvn clean compile process-aot -X' for verbose output to see the generated source path and inspect it.","If using GraalVM native, ensure spring-boot-starter-aot and the correct native build tools plugin are configured."],"exampleFix":"// before: AOT compile fails due to missing dependency on classpath\n// pom.xml missing a needed compile dependency\n// after: add the missing dependency so generated code resolves\n<dependency>\n  <groupId>com.example</groupId>\n  <artifactId>needed-lib</artifactId>\n</dependency>","handlingStrategy":"try-catch","validationCode":"// Before the AOT mojo, validate the classpath and target alignment.\n// Ensure -target/--release matches the JDK and all deps resolve.\norg.apache.maven.toolchain.Toolchain tc = toolchainManager.getToolchainFromBuildContext(\"jdk\", session);\nif (tc == null && System.getProperty(\"java.version\").startsWith(\"17\")) {\n    // warn: ensure target alignment to avoid generated-code compile failures\n}","typeGuard":null,"tryCatchPattern":"// Catch IllegalStateException around the AOT goal and surface compiler diagnostics.\ntry {\n    aotMojo.execute();\n} catch (IllegalStateException ex) {\n    if (ex.getMessage() != null && ex.getMessage().startsWith(\"Unable to compile generated source\")) {\n        // extract the appended Errors text, fix the root cause, re-run\n    }\n    throw ex;\n}","preventionTips":["Read the compiler diagnostics appended to the message — they identify the exact generated file and error.","Keep Spring Boot starter and spring-boot-maven-plugin versions aligned.","Ensure all compile dependencies needed at AOT time are present.","Align -target/--release with the build JDK version.","Run 'mvn clean process-aot -X' for verbose generated-source paths."],"tags":["maven","aot","compilation","native","spring-boot-plugin","generated-code"],"backgroundTag":null,"analyzedSha":"270dfe353fb830fd69b823a8a859287ff103854b","analyzedAt":"2026-08-11T19:42:06.541Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}