{"record":{"id":"5bb29a8fc53e2f88","repo":"quarkusio/quarkus","slug":"failed-to-delete-file","errorCode":null,"errorMessage":"Failed to delete file: ","messagePattern":"Failed to delete file: ","errorType":"exception","errorClass":"GradleException","httpStatus":null,"severity":"error","filePath":"devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/util/CustomFileSystemOperations.java","lineNumber":167,"sourceCode":"     * Deletes files and directories.\n     *\n     * @param action the delete action configuration\n     * @return the result of the delete operation\n     */\n    public WorkResult delete(Action<? super DeleteSpec> action) {\n        return getFs().delete(action);\n    }\n\n    /**\n     * Deletes a file if it exists.\n     *\n     * @param file the file to delete\n     */\n    public static void deleteFileIfExists(Path file) {\n        try {\n            Files.deleteIfExists(file);\n        } catch (IOException e) {\n            throw new GradleException(\"Failed to delete file: \" + file, e);\n        }\n    }\n\n    private static void configureCopyOrSyncOperation(CopySpec copy, CopySyncConfiguration config,\n            List<CopiedFileMetadata> copiedFilesMetadata) {\n        // iterate over sources to be able to pass each source path to the TimestampPreservingCopyAction\n        for (Path src : config.sources) {\n            copy.from(src, spec -> spec.eachFile(\n                    new TimestampPreservingCopyAction(\n                            src,\n                            config.destination,\n                            copiedFilesMetadata)));\n        }\n\n        copy.into(config.destination);\n\n        if (!config.includes.isEmpty()) {\n            copy.include(config.includes);","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/util/CustomFileSystemOperations.java#L149-L185","documentation":"CustomFileSystemOperations.deleteFileIfExists wraps Files.deleteIfExists; any IOException (e.g. file locked or in use) is rethrown as GradleException 'Failed to delete file: <path>'. It's used when the copy/sync operation must remove an existing destination file that is not writable before overwriting it.","triggerScenarios":"Executing a Quarkus copy/sync Gradle operation where an existing destination file must be deleted but Files.deleteIfExists throws IOException — destination file is locked by another process (IDE, running app, antivirus on Windows), read-only filesystem, or insufficient permissions on the parent directory.","commonSituations":"Windows: destination jar/classes locked by a running application or file indexer; Linux: read-only volume mount; destination inside a directory owned by another user; a previously failed build left immutable files.","solutions":["Close processes holding the file (stop the running Quarkus app, dev mode, IDE indexing) then retry.","Check and fix permissions: ensure the destination directory is writable by the build user.","On Windows, reboot or use handle.exe to find the locker; exclude the build dir from antivirus.","Free the mount if the destination is on a read-only filesystem."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"Path dest = ...;\nFile dir = dest.getParent().toFile();\nif (Files.exists(dest) && !Files.isWritable(dest)) throw new IllegalStateException(\"dest not writable: \" + dest);\nif (!dir.canWrite()) throw new IllegalStateException(\"dest dir not writable: \" + dir);","typeGuard":null,"tryCatchPattern":"try {\n    ./gradlew build\n} catch (GradleException e) {\n    if (e.getMessage().startsWith(\"Failed to delete file:\")) {\n        Path locked = Paths.get(e.getMessage().replace(\"Failed to delete file: \", \"\"));\n        // stop the process holding it, chmod, or clear read-only mount, then retry\n    }\n}","preventionTips":["Stop running Quarkus dev-mode/apps that lock build output before rebuilding","Keep build directories out of read-only mounts and off locked network shares","Exclude build/ from antivirus and file indexers (common on Windows)","Ensure the build user owns or has write access to the destination directory"],"tags":["gradle","io","filesystem","delete"],"backgroundTag":"file-delete-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"}