spring-projects/spring-boot · error · GradleException
Failed to read '{}'
Error message
Failed to read '{}' What it means
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.
Source
Thrown at build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ApplicationPluginAction.java:125
}
@Override
public Class<? extends Plugin<Project>> getPluginClass() {
return ApplicationPlugin.class;
}
private String loadResource(String name) {
try (InputStreamReader reader = new InputStreamReader(getResourceAsStream(name))) {
char[] buffer = new char[4096];
int read;
StringWriter writer = new StringWriter();
while ((read = reader.read(buffer)) > 0) {
writer.write(buffer, 0, read);
}
return writer.toString();
}
catch (IOException ex) {
throw new GradleException("Failed to read '" + name + "'", ex);
}
}
private InputStream getResourceAsStream(String name) {
InputStream stream = getClass().getResourceAsStream(name);
Assert.state(stream != null, "Resource '%s' not found'".formatted(name));
return stream;
}
private void configureFilePermissions(CopySpec copySpec, int mode) {
if (GradleVersion.current().compareTo(GradleVersion.version("8.3")) >= 0) {
copySpec.filePermissions((filePermissions) -> filePermissions.unix(Integer.toString(mode, 8)));
}
else {
configureFileMode(copySpec, mode);
}
}
View on GitHub (pinned to 5b2dbdbb8b)
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.
Example fix
// build.gradle.kts — force a clean re-download of the plugin // then re-sync // shell: // ./gradlew --refresh-dependencies build
Defensive patterns
Strategy: try-catch
Validate before calling
// Verify the bundled templates exist in the resolved plugin jar before applying
import java.util.jar.JarFile
fun pluginTemplatesIntact(pluginJar: java.io.File): Boolean {
JarFile(pluginJar).use { jar ->
return jar.getJarEntry("unixStartScript.txt") != null &&
jar.getJarEntry("windowsStartScript.txt") != null
}
}
Try / catch
try {
project.pluginManager.apply("org.springframework.boot")
} catch (ex: org.gradle.api.GradleException) {
if (ex.message?.startsWith("Failed to read '") == true) {
logger.error("Spring Boot plugin resources are missing/corrupt. " +
"Clear ~/.gradle/caches and re-resolve the plugin.")
}
throw ex
}
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to set file mode on CopySpec
- Main class name has not been configured and it could not be
- Failed to read main class name from '{}'
- Failed to create {}
- Failed to add {} to {}
AI-assisted analysis of spring-projects/spring-boot@5b2dbdbb8b (2026-08-04).
Data as JSON: /data/errors/7b3de5608b551d21.json.
Report an issue: GitHub.