quarkusio/quarkus · error · CodeGenException

Failed to generate Java classes from proto files: %s to %s w

Error message

Failed to generate Java classes from proto files: %s to %s with command %s

What it means

GrpcCodeGen.trigger invokes the protoc binary via the protobuf plugin's ProcessBuilder helper to generate Java sources from .proto files. Any exception from the protoc invocation is wrapped in a CodeGenException that names the proto files, output directory, and exact command line — this is the canonical 'protoc failed' build error in Quarkus gRPC.

Source

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

                        for (int i = 1; i < command.size(); i++) {
                            writer.println(command.get(i));
                        }
                    }

                    command = new ArrayList<>(List.of(command.get(0), "@" + argFile.getAbsolutePath()));
                }
                log.debugf("Executing command: %s", String.join(" ", command));
                try {
                    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";

View on GitHub (pinned to e1c734241f)

Solutions

  1. Read the highlighted protoc output above the exception (the outputConsumer prints relevant errors) for the exact .proto error line
  2. Fix the reported .proto syntax/import errors in src/main/proto
  3. Verify the output directory is writable and the platform has a compatible protoc binary; clean and rebuild (./mvnw clean install)

Example fix

// before
// src/main/proto/item.proto
syntax = "proto3";
message Item { int32 id = 1; string name = ; } // syntax error
// after
syntax = "proto3";
message Item { int32 id = 1; string name = 2; }
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-check proto files before building:
for (f in src/main/proto/*.proto) {
    assert f.text.startsWith('syntax'); // every proto must declare syntax
}
assert file('src/main/proto').canRead()
assert file('target/generated-sources').parentFile.canWrite()

Try / catch

try {
    mvn clean install;
} catch (CodeGenException e) {
    // message names protos, out dir, and command; read the highlighted protoc lines above
    System.err.println(e.getMessage());
    Throwable root = e.getCause();
    while (root != null) { System.err.println(root); root = root.getCause(); }
}

Prevention

When it happens

Trigger: Building a Quarkus app where protoc fails: missing/incompatible protoc binary for the platform, invalid .proto syntax, proto files importing unavailable files, or protoc exiting with a non-zero code.

Common situations: Unsupported OS/arch (no prebuilt protoc binary); proto files with syntax errors or missing imports; permission issues on the output directory; corporate proxies blocking protoc artifact download in older versions.

Related errors


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