quarkusio/quarkus · error · CodeGenException

Failed to copy compiled files to output directory ${outputDi

Error message

Failed to copy compiled files to output directory ${outputDirectory.toAbsolutePath()}

What it means

After compiling the schema, SpecificCompiler.compileToDestination writes generated Java sources into the target output directory. If that write fails with IOException, Quarkus wraps it in this CodeGenException reporting the output directory path. It means generated sources could not be written/copied to disk.

Source

Thrown at extensions/avro/deployment/src/main/java/io/quarkus/avro/deployment/AvroSchemaCodeGenProvider.java:85

        compiler.setEnableDecimalLogicalType(options.enableDecimalLogicalType);
        compiler.setOutputCharacterEncoding("UTF-8");
        compiler.addCustomConversion(Conversions.UUIDConversion.class);

        for (String customConversion : options.customConversions) {
            try {
                Class<?> conversionClass = Class.forName(customConversion);
                if (!conversionClass.isInstance(Conversions.UUIDConversion.class)) {
                    compiler.addCustomConversion(conversionClass);
                }
            } catch (ClassNotFoundException e) {
                throw new CodeGenException("Unable to find the following conversion class: " + customConversion, e);
            }
        }

        try {
            compiler.compileToDestination(file, outputDirectory.toFile());
        } catch (IOException e) {
            throw new CodeGenException("Failed to copy compiled files to output directory " +
                    outputDirectory.toAbsolutePath(), e);
        }
    }
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Check write permissions on the reported output directory (and fix ownership if created by root/docker)
  2. Run mvn clean to remove a stale/locked target directory and rebuild
  3. Ensure the output path is a directory, not a file, and the disk has free space
  4. On CI, verify the workspace mount is writable

Example fix

// shell, before
ls -ld target/generated-sources/avro  # owned by root, not writable
// after
sudo chown -R $(whoami) target && ./mvnw clean compile
Defensive patterns

Strategy: validation

Validate before calling

Path out = Path.of("target/generated-sources/avro");
if (Files.exists(out) && !Files.isDirectory(out)) {
    throw new IllegalStateException("Output path is a file, not a directory: " + out);
}
if (!Files.isWritable(out.getParent() != null ? out.getParent() : Path.of("target"))) {
    throw new IllegalStateException("Output directory not writable: " + out);
}

Try / catch

try {
    project.build();
} catch (CodeGenException e) {
    log.error("Cannot write generated Avro sources: " + e.getMessage());
    log.error("Check permissions/ownership of the output directory");
}

Prevention

When it happens

Trigger: compileToDestination throws while writing generated .java files: output dir is not writable, is a file instead of a directory, or disk I/O fails.

Common situations: target/ directory locked or owned by another user (e.g. files created by a container as root); read-only filesystem in CI; path conflict where outputDirectory exists as a regular file; full disk.

Related errors


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