quarkusio/quarkus · error · CodeGenException

Failed to generate java files from proto file in " + inputDi

Error message

Failed to generate java files from proto file in " + inputDir.toAbsolutePath()

What it means

GrpcCodeGen.trigger wraps any IOException occurring during the proto-file setup/generation workflow into a CodeGenException naming the input directory. Unlike the protoc-execution error, this indicates a filesystem/IO problem before or around the generation step, not a proto compilation error.

Source

Thrown at extensions/grpc/codegen/src/main/java/io/quarkus/grpc/codegen/GrpcCodeGen.java:219

                    ProcessBuilder<Void> pb = ProcessBuilder.newBuilder(command.get(0),
                            command.subList(1, command.size()));
                    // Tune the environment for compatibility with Java >24 without triggering warnings
                    pb.modifyEnvironment(GrpcCodeGen::invocationEnvironmentTuning);
                    // Set up a custom output handler to highlight only relevant errors
                    pb.output().consumeLinesWith(100, this::outputConsumer);
                    pb.error().consumeLinesWith(100, this::outputConsumer).logOnSuccess(false);
                    pb.run();
                } catch (Exception e) {
                    throw new CodeGenException("Failed to generate Java classes from proto files: %s to %s with command %s"
                            .formatted(protoFiles, outDir.toAbsolutePath(), String.join(" ", command)), e);
                }
                postprocessing(context, outDir);
                log.info("Successfully finished generating and post-processing sources from proto files");

                return true;
            }
        } catch (IOException e) {
            throw new CodeGenException(
                    "Failed to generate java files from proto file in " + inputDir.toAbsolutePath(), e);
        }

        return false;
    }

    private static void invocationEnvironmentTuning(final Map<String, String> environment) {
        //This specific environment variable is being picked up by the JVMs spawned by protoc:
        final String key = "JDK_JAVA_OPTIONS";
        String existingValue = environment.get(key);
        if (existingValue == null || existingValue.isBlank()) {
            existingValue = "";
        }
        StringBuilder sb = new StringBuilder();
        //Each of these require custom logic to ensure we don't override an explicit user setting

        if (!existingValue.contains("-Dsun.stdout.encoding=")) {
            //This one is always useful, especially on Java 17:

View on GitHub (pinned to e1c734241f)

Solutions

  1. Check the caused-by IOException for the exact file/path and OS reason
  2. Verify src/main/proto exists with read permission and target/generated-sources is writable
  3. Stop competing processes (dev mode, IDE watchers) locking the output dir, clean, and rebuild

Example fix

// before
// CI running as user without write access to target/
mvn verify // CodeGenException: Failed to generate java files from proto file in .../src/main/proto
// after
# grant write access or set a writable build output
chmod -R u+w target && mvn verify
Defensive patterns

Strategy: validation

Validate before calling

File protoDir = new File("src/main/proto");
if (!protoDir.canRead()) throw new IllegalStateException("Cannot read proto dir: " + protoDir);
File out = new File("target/generated-sources");
if (out.exists() && !out.canWrite()) throw new IllegalStateException("Output dir not writable: " + out);

Try / catch

try {
    mvn clean install;
} catch (CodeGenException e) {
    if (e.getCause() instanceof IOException ioe) {
        System.err.println("Filesystem problem during codegen: " + ioe.getMessage());
    }
}

Prevention

When it happens

Trigger: Building with the Quarkus gRPC code generator when the proto input directory cannot be read or the output directory cannot be created/written: missing src/main/proto directory handling paths, locked files, or disk/full-permission failures.

Common situations: Read-only working directories in CI; files locked by a running dev-mode process on Windows; disk quota exceeded; inputDir deleted by an aggressive clean rule while the build runs.

Related errors


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