quarkusio/quarkus · error · GradleException

Failed to generate sources in the QuarkusGenerateCode task f

Error message

Failed to generate sources in the QuarkusGenerateCode task for 

What it means

CodeGenWorker.execute invokes the reflectively obtained code generator and catches BootstrapException, IllegalAccessException, InvocationTargetException, and ClassNotFoundException, rethrowing as GradleException with the GAV and exception embedded in the message (since Gradle abbreviates stack traces). It means the code generation phase itself failed at runtime for this project.

Source

Thrown at devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/worker/CodeGenWorker.java:89

                            params.getSourceDirectories().getFiles().stream().map(File::toPath).collect(Collectors.toList())),
                    // Path generatedSourcesDir,
                    generatedSourceDir,
                    // Path buildDir,
                    buildDir,
                    // Consumer<Path> sourceRegistrar,
                    sourceRegistrar,
                    // ApplicationModel appModel,
                    appCreationContext.getApplicationModel(),
                    // Properties properties,
                    props,
                    // String launchMode,
                    launchMode.name(),
                    // boolean test
                    launchMode == LaunchMode.TEST);
        } catch (BootstrapException | IllegalAccessException | InvocationTargetException | ClassNotFoundException e) {
            // Gradle "abbreviates" the stacktrace to something human-readable, but here the underlying cause might
            // get lost in the error output, so add 'e' to the message.
            throw new GradleException("Failed to generate sources in the QuarkusGenerateCode task for " + gav + " due to " + e,
                    e);
        }
    }
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Read the 'due to ...' cause — for InvocationTargetException inspect its cause for the real generator error.
  2. Fix the offending input file flagged by the generator (e.g. malformed schema/OpenAPI spec).
  3. Clean build outputs and re-run: ./gradlew clean quarkusGenerateCode.
  4. Align Quarkus core and generator extension versions.
  5. Restart the Gradle daemon to clear stale classloaders.
Defensive patterns

Strategy: try-catch

Validate before calling

./gradlew clean quarkusGenerateCode --info  # clean run reveals the failing generator/input
git diff --stat build/generated-sources 2>/dev/null # spot stale outputs

Try / catch

try {
    ./gradlew quarkusGenerateCode
} catch (GradleException e) {
    if (e.getMessage().startsWith("Failed to generate sources in the QuarkusGenerateCode task")) {
        Throwable root = e;
        while (root.getCause() != null) root = root.getCause(); // InvocationTargetException hides the real error
        System.err.println(root);
    }
}

Prevention

When it happens

Trigger: Running quarkusGenerateCode where the generator bootstrap fails (BootstrapException), the reflective initAndRun invocation throws inside the generator (InvocationTargetException), the CodeGenerator class can't be loaded (ClassNotFoundException), or access is denied (IllegalAccessException).

Common situations: Broken/generator extension jars on the classpath after partial upgrades; invalid generator input (bad OpenAPI/Avro/protobuf sources); Java module/access issues; missing generator class because the providing extension wasn't applied; stale classloader state in the Gradle daemon.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/7825d258f7343119. Report an issue: GitHub.