{"record":{"id":"d809a9fa96e36e0e","repo":"quarkusio/quarkus","slug":"failed-to-copy-file-artifactpath-to-exe","errorCode":null,"errorMessage":"Failed to copy file: ${artifactPath} to ${exe}","messagePattern":"Failed to copy file: (.+?) to (.+?)","errorType":"exception","errorClass":"CodeGenException","httpStatus":null,"severity":"error","filePath":"extensions/grpc/codegen/src/main/java/io/quarkus/grpc/codegen/GrpcCodeGen.java","lineNumber":519,"sourceCode":"    }\n\n    private Path makeExecutableFromPath(Path buildDir, String groupId, String artifactId, String classifier, String packaging,\n            Path artifactPath) throws CodeGenException {\n        Path exe = buildDir.resolve(String.format(\"%s-%s-%s-%s\", groupId, artifactId, classifier, packaging));\n\n        if (Files.exists(exe)) {\n            return exe;\n        }\n\n        if (artifactPath == null) {\n            String location = String.format(\"%s:%s:%s:%s\", groupId, artifactId, classifier, packaging);\n            throw new CodeGenException(\"Failed to find \" + location + \" among dependencies\");\n        }\n\n        try {\n            Files.copy(artifactPath, exe, StandardCopyOption.REPLACE_EXISTING);\n        } catch (IOException e) {\n            throw new CodeGenException(\"Failed to copy file: \" + artifactPath + \" to \" + exe, e);\n        }\n        if (!exe.toFile().setExecutable(true)) {\n            throw new CodeGenException(\"Failed to make the file executable: \" + exe);\n        }\n        return exe;\n    }\n\n    private static Path findArtifactPath(ApplicationModel model, String groupId, String artifactId, String classifier,\n            String packaging) {\n        Path artifactPath = null;\n\n        for (ResolvedDependency artifact : model.getDependencies()) {\n            if (groupId.equals(artifact.getGroupId())\n                    && artifactId.equals(artifact.getArtifactId())\n                    && classifier.equals(artifact.getClassifier())\n                    && packaging.equals(artifact.getType())) {\n                artifactPath = artifact.getResolvedPaths().getSinglePath();\n            }","sourceCodeStart":501,"sourceCodeEnd":537,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/grpc/codegen/src/main/java/io/quarkus/grpc/codegen/GrpcCodeGen.java#L501-L537","documentation":"After locating the protoc/protoc-gen-grpc-java artifact, Quarkus copies it from the local repository into the build directory as the executable. This CodeGenException wraps an IOException from Files.copy, meaning the JAR could not be copied (unreadable source or unwritable/occupied target path).","triggerScenarios":"Code generation where buildDir/<groupId>-<artifactId>-<classifier>-<packaging> cannot be written — target path exists as a directory, parent dir is read-only, or source artifact path is unreadable/locked.","commonSituations":"Stale build dirs where a directory replaced the expected file; Maven repo cache partially downloaded; Windows file locking by antivirus or a previous crashed build; read-only container filesystems.","solutions":["Run mvn clean / gradle clean and rebuild to remove the conflicting path in target","Check permissions on both the artifact in ~/.m2 (or Gradle cache) and the build output directory","Re-download the artifact if the cached copy is corrupt or partially downloaded","On Windows, exclude target/ from antivirus real-time scanning and stop processes holding the file"],"exampleFix":"// before: stale path occupying the exe location\nls target/ # com.google.protobuf-protoc-linux-x86_64-exe is a directory\n// after\ncd . && mvn clean compile","handlingStrategy":"validation","validationCode":"Path exe = buildDir.resolve(\"com.google.protobuf-protoc-\" + classifier + \"-exe\");\nif (Files.exists(exe) && !Files.isRegularFile(exe)) {\n    throw new IllegalStateException(exe + \" exists but is not a regular file; run mvn clean\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    build.run();\n} catch (CodeGenException e) {\n    if (e.getMessage().startsWith(\"Failed to copy file:\")) {\n        exec(\"mvn clean\"); // then retry the build once\n        build.run();\n    }\n}","preventionTips":["Run mvn clean after abnormal build terminations","Ensure the local repository cache is healthy (delete partial downloads)","Avoid sharing one target/ between concurrent builds","Exclude build output from file-locking software on Windows"],"tags":["io","filesystem","grpc","codegen"],"backgroundTag":"file-copy-failed","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}