spring-projects/spring-boot · error · IllegalStateException
Unable to compile generated source
Error message
Unable to compile generated source{} What it means
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.
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.
Example fix
// before: AOT compile fails due to missing dependency on classpath // pom.xml missing a needed compile dependency // after: add the missing dependency so generated code resolves <dependency> <groupId>com.example</groupId> <artifactId>needed-lib</artifactId> </dependency>
Defensive patterns
Strategy: try-catch
Validate before calling
// Before the AOT mojo, validate the classpath and target alignment.
// Ensure -target/--release matches the JDK and all deps resolve.
org.apache.maven.toolchain.Toolchain tc = toolchainManager.getToolchainFromBuildContext("jdk", session);
if (tc == null && System.getProperty("java.version").startsWith("17")) {
// warn: ensure target alignment to avoid generated-code compile failures
} Try / catch
// Catch IllegalStateException around the AOT goal and surface compiler diagnostics.
try {
aotMojo.execute();
} catch (IllegalStateException ex) {
if (ex.getMessage() != null && ex.getMessage().startsWith("Unable to compile generated source")) {
// extract the appended Errors text, fix the root cause, re-run
}
throw ex;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid URL for
- Failed to read
- Main class name has not been configured and it could not be…
- Spring Boot plugin requires Gradle 8.x (8.14 or later) or…
- Unable to find ' ' dependency. Please ensure JUnit is…
AI-assisted analysis of spring-projects/spring-boot@270dfe353f (2026-08-11).
Data as JSON: /api/errors/abeeb0764079902a.
Report an issue: GitHub.
Appendix: source
Thrown at build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractAotMojo.java:180
String source = compilerConfiguration.getSourceMajorVersion();
if (source != null) {
args.add("--source");
args.add(source);
}
String target = compilerConfiguration.getTargetMajorVersion();
if (target != null) {
args.add("--target");
args.add(target);
}
}
args.add("-parameters");
args.addAll(new RunArguments(this.compilerArguments).getArgs());
Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromPaths(sourceFiles);
Errors errors = new Errors();
CompilationTask task = compiler.getTask(null, fileManager, errors, args, null, compilationUnits);
boolean result = task.call();
if (!result || errors.hasReportedErrors()) {
throw new IllegalStateException("Unable to compile generated source" + errors);
}
}
}
protected final URL[] getClassPath(File[] directories, ArtifactsFilter... artifactFilters)
throws MojoExecutionException {
List<URL> urls = new ArrayList<>();
Arrays.stream(directories).map(this::toURL).forEach(urls::add);
urls.addAll(getDependencyURLs(artifactFilters));
return urls.toArray(URL[]::new);
}
protected final void copyAll(Path from, Path to) throws IOException {
if (!Files.exists(from)) {
return;
}
List<Path> files;
try (Stream<Path> pathStream = Files.walk(from)) {View on GitHub (pinned to 270dfe353f)