{"id":"7b3de5608b551d21","repo":"spring-projects/spring-boot","slug":"failed-to-read","errorCode":null,"errorMessage":"Failed to read '{}'","messagePattern":"Failed to read '(.+?)'","errorType":"exception","errorClass":"GradleException","httpStatus":null,"severity":"error","filePath":"build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ApplicationPluginAction.java","lineNumber":125,"sourceCode":"\t}\n\n\t@Override\n\tpublic Class<? extends Plugin<Project>> getPluginClass() {\n\t\treturn ApplicationPlugin.class;\n\t}\n\n\tprivate String loadResource(String name) {\n\t\ttry (InputStreamReader reader = new InputStreamReader(getResourceAsStream(name))) {\n\t\t\tchar[] buffer = new char[4096];\n\t\t\tint read;\n\t\t\tStringWriter writer = new StringWriter();\n\t\t\twhile ((read = reader.read(buffer)) > 0) {\n\t\t\t\twriter.write(buffer, 0, read);\n\t\t\t}\n\t\t\treturn writer.toString();\n\t\t}\n\t\tcatch (IOException ex) {\n\t\t\tthrow new GradleException(\"Failed to read '\" + name + \"'\", ex);\n\t\t}\n\t}\n\n\tprivate InputStream getResourceAsStream(String name) {\n\t\tInputStream stream = getClass().getResourceAsStream(name);\n\t\tAssert.state(stream != null, \"Resource '%s' not found'\".formatted(name));\n\t\treturn stream;\n\t}\n\n\tprivate void configureFilePermissions(CopySpec copySpec, int mode) {\n\t\tif (GradleVersion.current().compareTo(GradleVersion.version(\"8.3\")) >= 0) {\n\t\t\tcopySpec.filePermissions((filePermissions) -> filePermissions.unix(Integer.toString(mode, 8)));\n\t\t}\n\t\telse {\n\t\t\tconfigureFileMode(copySpec, mode);\n\t\t}\n\t}\n","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/spring-projects/spring-boot/blob/5b2dbdbb8be64415eb6552f81ff7c449c8d251e6/build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ApplicationPluginAction.java#L107-L143","documentation":"Thrown by ApplicationPluginAction.loadResource() when reading the bundled start-script templates (/unixStartScript.txt, /windowsStartScript.txt) from the plugin jar's classpath fails with IOException, wrapped as a GradleException. These templates are required to generate bootStartScripts for the 'boot' distribution. The plugin ships them inside its own jar, so a read failure means the plugin artifact is damaged or its classloader is misconfigured.","triggerScenarios":"Applying the Gradle 'application' plugin alongside Spring Boot triggers ApplicationPluginAction.execute(), which calls loadResource() for unixStartScript.txt and windowsStartScript.txt; an IOException while streaming either resource from getClass().getResourceAsStream(name) reaches line 125.","commonSituations":"The spring-boot-gradle-plugin jar got corrupted/partially downloaded in the Gradle cache; a custom build shades or relocates the plugin and strips the template resources; a broken filesystem or interrupted download left the jar incomplete; an unusual classloader (some fat-jar/monorepo tooling) hides plugin-internal resources.","solutions":["Clear the Gradle cache for the plugin and re-resolve: rm -rf ~/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-gradle-plugin then refresh dependencies.","Verify the plugin jar is intact: list the archive contents (jar tf) and confirm /unixStartScript.txt and /windowsStartScript.txt are present.","Remove any shadow/shade/dependency-reduce tricks that relocate or strip resources from the spring-boot-gradle-plugin; load it as a normal classpath dependency.","Pin an uncorrupted plugin version in your buildscript/plugins block and run with --refresh-dependencies."],"exampleFix":"// build.gradle.kts — force a clean re-download of the plugin\n// then re-sync\n// shell:\n//   ./gradlew --refresh-dependencies build\n","handlingStrategy":"try-catch","validationCode":"// Verify the bundled templates exist in the resolved plugin jar before applying\nimport java.util.jar.JarFile\n\nfun pluginTemplatesIntact(pluginJar: java.io.File): Boolean {\n    JarFile(pluginJar).use { jar ->\n        return jar.getJarEntry(\"unixStartScript.txt\") != null &&\n               jar.getJarEntry(\"windowsStartScript.txt\") != null\n    }\n}\n","typeGuard":null,"tryCatchPattern":"try {\n    project.pluginManager.apply(\"org.springframework.boot\")\n} catch (ex: org.gradle.api.GradleException) {\n    if (ex.message?.startsWith(\"Failed to read '\") == true) {\n        logger.error(\"Spring Boot plugin resources are missing/corrupt. \" +\n            \"Clear ~/.gradle/caches and re-resolve the plugin.\")\n    }\n    throw ex\n}\n","preventionTips":["Do not shade, relocate, or strip resources from the spring-boot-gradle-plugin.","Pin the plugin version explicitly and keep the Gradle dependency cache healthy.","Run --refresh-dependencies after cache corruption or interrupted downloads."],"tags":["gradle","plugin-integrity","resource","io","application-plugin"],"analyzedSha":"5b2dbdbb8be64415eb6552f81ff7c449c8d251e6","analyzedAt":"2026-08-04T18:53:14.967Z","schemaVersion":2}