quarkusio/quarkus · error · CodeGenException

Failed to create output directory for generated sources: %s

Error message

Failed to create output directory for generated sources: %s

What it means

CodeGenException thrown by codeGenOutDir when Files.createDirectories(outputDir) fails while preparing the output directory for a code generator provider's generated sources (target/generated-sources/src/<providerId>). The IOException (usually permissions or an existing non-directory file at that path) is wrapped in a descriptive CodeGenException. Build aborts before code generation runs.

Source

Thrown at core/deployment/src/main/java/io/quarkus/deployment/CodeGenerator.java:412

                // Always return null to let MultiRootPathTree.apply() look into all roots.
                return null;
            });
            return unavailableServices;
        } catch (IOException e) {
            throw new CodeGenException("Failed to read " + dep.getResolvedPaths(), e);
        }
    }

    private static Path codeGenOutDir(Path generatedSourcesDir,
            CodeGenProvider provider,
            Consumer<Path> sourceRegistrar) throws CodeGenException {
        Path outputDir = generatedSourcesDir.resolve(provider.providerId());
        try {
            Files.createDirectories(outputDir);
            sourceRegistrar.accept(outputDir);
            return outputDir;
        } catch (IOException e) {
            throw new CodeGenException(
                    "Failed to create output directory for generated sources: " + outputDir.toAbsolutePath(), e);
        }
    }

    @FunctionalInterface
    private interface CodeGenAction<T> {
        T fire() throws CodeGenException;
    }
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Delete the offending path shown in the message (or the whole target dir) so the directory can be created, then rebuild
  2. Verify write permissions on the project directory and that the build user owns target/
  3. Free disk space / resolve quota limits on the build volume
  4. Run as a user with sufficient filesystem rights in CI containers

Example fix

# before: a file exists where the directory should be
target/generated-sources/src/hibernate-orm  # plain file
# after
rm -rf target/generated-sources && mvn quarkus:build
Defensive patterns

Strategy: validation

Validate before calling

Path out = generatedSourcesDir.resolve(provider.providerId());
if (out.toFile().exists() && !out.toFile().isDirectory()) {
    throw new IllegalStateException("Not a directory: " + out + " — delete it and rebuild");
}
if (!Files.isWritable(generatedSourcesDir)) {
    throw new IllegalStateException("No write permission on " + generatedSourcesDir);
}

Try / catch

try {
    Files.createDirectories(outputDir);
} catch (IOException e) {
    throw new IllegalStateException("Check permissions/disk for " + outputDir + ": " + e.getMessage(), e);
}

Prevention

When it happens

Trigger: During code generation setup, outputDir = generatedSourcesDir.resolve(provider.providerId()) cannot be created because a parent path is a file, the disk is full, or the process lacks write permission on target/generated-sources.

Common situations: Read-only project directory (checkout mounted read-only, CI running with wrong user); target/generated-sources path exists as a regular file (rarely, from a broken previous build); disk quota exceeded; Windows path/permission problems.

Related errors


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