quarkusio/quarkus · error · GrpcCodeGenException

Failed to extract proto file" + path + " to target: " + outP

Error message

Failed to extract proto file" + path + " to target: " + outPath

What it means

After creating the destination directory, Quarkus gRPC codegen copies each .proto file from the scanned dependency artifact to the work directory (sanitizing dependency protos). If Files.copy or copySanitizedProtoFile throws an IOException, the build fails with this GrpcCodeGenException naming the source proto file and target path.

Source

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

                        if (Files.isRegularFile(path) && path.getFileName().toString().endsWith(PROTO)) {
                            String strippedPathStr = stripProtoPrefix(pathVisit.getResourceName());
                            try {
                                Files.createDirectories(protoOutputDir);
                                protoDirectories.add(protoOutputDir.toString());
                            } catch (IOException e) {
                                throw new GrpcCodeGenException("Failed to create directory: " + protoOutputDir, e);
                            }
                            Path outPath = protoOutputDir.resolve(strippedPathStr);
                            try {
                                Files.createDirectories(outPath.getParent());
                                if (isDependency) {
                                    copySanitizedProtoFile(artifact, path, outPath);
                                } else {
                                    Files.copy(path, outPath, StandardCopyOption.REPLACE_EXISTING);
                                }
                                protoFiles.add(outPath);
                            } catch (IOException e) {
                                throw new GrpcCodeGenException("Failed to extract proto file" + path + " to target: "
                                        + outPath, e);
                            }
                        }
                    });
        } catch (GrpcCodeGenException e) {
            throw new CodeGenException(e.getMessage(), e);
        }
    }

    private static String stripProtoPrefix(String relativePathStr) {
        if (relativePathStr.startsWith(SRC_MAIN_PROTO_DIR)) {
            return relativePathStr.substring(SRC_MAIN_PROTO_DIR.length());
        }
        if (relativePathStr.startsWith(SRC_TEST_PROTO_DIR)) {
            return relativePathStr.substring(SRC_TEST_PROTO_DIR.length());
        }
        if (relativePathStr.startsWith(PROTO_DIR)) {
            return relativePathStr.substring(PROTO_DIR.length());

View on GitHub (pinned to e1c734241f)

Solutions

  1. Run a clean build (mvn clean or gradle clean) to remove stale/partially copied protos in target
  2. Verify the source JAR in the local Maven repository is intact (delete it and let Maven/Gradle re-download)
  3. Check filesystem permissions on both the artifact JAR and the build output directory
  4. Close processes locking files on Windows (antivirus, IDE indexing) or exclude the build dir from real-time scanning
  5. Ensure disk space is available on the volume hosting the build directory

Example fix

// before: corrupted cached artifact
~/.m2/repository/com/example/proto-deps/1.0/proto-deps-1.0.jar (truncated)
// after: force re-download
rm ~/.m2/repository/com/example/proto-deps/1.0/proto-deps-1.0.jar
mvn clean compile
Defensive patterns

Strategy: validation

Validate before calling

// verify the dependency JAR containing protos is readable before building
Path jar = Paths.get(System.getProperty("user.home"), ".m2/repository/com/example/proto-deps/1.0/proto-deps-1.0.jar");
if (!Files.isReadable(jar) || jar.size() == 0) throw new IllegalStateException("Artifact unreadable or corrupt: " + jar);

Try / catch

try {
    mvnRunner.run("compile");
} catch (BuildFailure e) {
    if (e.getMessage().contains("Failed to extract proto file")) {
        Files.deleteIfExists(cachedArtifact); // then rebuild to re-download
    }
}

Prevention

When it happens

Trigger: Running quarkus:dev / mvn compile with grpc code generation where a dependency contains .proto files, and copying a proto fails due to missing permissions on the source or target, the source file disappearing mid-walk, or the target path colliding with a non-directory.

Common situations: Source JAR partially downloaded or locked by another process (Windows antivirus/indexer); target/ owned by another user; disk full; network-mounted workspace with flaky I/O; parallel builds racing over the same target directory.

Related errors


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