{"id":"78da5af1948daf8d","repo":"spring-projects/spring-boot","slug":"failed-to-add-to","errorCode":null,"errorMessage":"Failed to add {} to {}","messagePattern":"Failed to add (.+?) to (.+?)","errorType":"exception","errorClass":"GradleException","httpStatus":null,"severity":"error","filePath":"build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootZipCopyAction.java","lineNumber":222,"sourceCode":"\t\t\tthis.layerIndex = (BootZipCopyAction.this.layerResolver != null)\n\t\t\t\t\t? new LayersIndex(BootZipCopyAction.this.layerResolver.getLayers()) : null;\n\t\t}\n\n\t\tvoid process(FileCopyDetails details) {\n\t\t\tif (skipProcessing(details)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\twriteLoaderEntriesIfNecessary(details);\n\t\t\t\tif (details.isDirectory()) {\n\t\t\t\t\tprocessDirectory(details);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tprocessFile(details);\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (IOException ex) {\n\t\t\t\tthrow new GradleException(\"Failed to add \" + details + \" to \" + BootZipCopyAction.this.output, ex);\n\t\t\t}\n\t\t}\n\n\t\tprivate boolean skipProcessing(FileCopyDetails details) {\n\t\t\treturn BootZipCopyAction.this.exclusions.isSatisfiedBy(details)\n\t\t\t\t\t|| (this.writtenLoaderEntries != null && this.writtenLoaderEntries.isWrittenDirectory(details));\n\t\t}\n\n\t\tprivate void processDirectory(FileCopyDetails details) throws IOException {\n\t\t\tString name = details.getRelativePath().getPathString();\n\t\t\tZipArchiveEntry entry = new ZipArchiveEntry(name + '/');\n\t\t\tprepareEntry(entry, name, getTime(details), getDirMode(details));\n\t\t\tthis.out.putArchiveEntry(entry);\n\t\t\tthis.out.closeArchiveEntry();\n\t\t\tthis.writtenDirectories.add(name);\n\t\t}\n\n\t\tprivate void processFile(FileCopyDetails details) throws IOException {","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/spring-projects/spring-boot/blob/5b2dbdbb8be64415eb6552f81ff7c449c8d251e6/build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootZipCopyAction.java#L204-L240","documentation":"Thrown by BootZipCopyAction.Processor.process() when writing a single FileCopyDetails into the archive raises IOException, wrapped as GradleException naming both the entry (details) and the target archive. It is per-entry granularity: the message tells you exactly which file could not be added to which archive.","triggerScenarios":"For each entry, process() writes loader/directory/file; if details.copyTo(out) or putArchiveEntry/closeArchiveEntry throws IOException, line 222 wraps it with 'Failed to add <details> to <output>'.","commonSituations":"A source file vanishes between scanning and copying (mid-build deletion); a corrupted/locked input jar; oversized entry; filesystem errors on the build volume; an input dependency is unreadable.","solutions":["Inspect the message for the specific entry path and verify that file is readable and present.","Run ./gradlew clean to ensure inputs are regenerated from scratch.","If the failing entry is a dependency jar, re-resolve dependencies (--refresh-dependencies) to replace a corrupt cached artifact.","Check for locked/missing source files (IDE/OS-level) and free disk space."],"exampleFix":"// shell: reproduce with clean + refresh deps\n//   ./gradlew clean bootJar --refresh-dependencies --info\n","handlingStrategy":"try-catch","validationCode":"// Pre-check that all inputs to bootJar are readable\nsourceSets.main.get().output.files.forEach { d ->\n    require(d.canRead()) { \"Cannot read source dir ${d.absolutePath}\" }\n}\nconfigurations.runtimeClasspath.get().files.forEach { f ->\n    require(f.canRead()) { \"Cannot read dependency ${f.absolutePath}\" }\n}\n","typeGuard":null,"tryCatchPattern":"try {\n    tasks.named(\"bootJar\").get().copy()\n} catch (ex: org.gradle.api.GradleException) {\n    if (ex.message?.startsWith(\"Failed to add \") == true) {\n        logger.error(\"A specific entry could not be added; see the file named in the message.\")\n    }\n    throw ex\n}\n","preventionTips":["Run ./gradlew clean so all inputs are freshly produced.","Use --refresh-dependencies when a cached dependency jar is suspect.","Avoid modifying/killing source files during the build."],"tags":["gradle","boot-archive","io","copy","per-entry"],"analyzedSha":"5b2dbdbb8be64415eb6552f81ff7c449c8d251e6","analyzedAt":"2026-08-04T18:53:14.967Z","schemaVersion":2}