spring-projects/spring-boot · error · RuntimeException

Failed to set file mode on CopySpec

Error message

Failed to set file mode on CopySpec

What it means

Thrown by ApplicationPluginAction.configureFileMode, the legacy fallback path that uses reflection to invoke CopySpec.setFileMode(Integer) on Gradle versions older than 8.3 (the code above checks GradleVersion 8.3 to decide between the modern filePermissions API and this reflective path). The exception wraps any reflection failure: NoSuchMethodException, IllegalAccessException, or InvocationTargetException.

Solutions

  1. Upgrade Gradle to 8.3 or later, which uses the modern filePermissions API and avoids this reflective path entirely.
  2. If you must stay on an older Gradle, ensure no custom CopySpec implementation overrides the default Gradle API surface.
  3. Check for conflicting plugins that replace or wrap CopySpec types and remove or update them.

Example fix

// before: running on Gradle 7.x with spring-boot-gradle-plugin
// Upgrade gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
// after: Gradle 8.14+ uses filePermissions() directly, never hits configureFileMode reflection
Defensive patterns

Strategy: validation

Validate before calling

// In settings.gradle or build.gradle, gate the plugin on Gradle version before apply.
if (GradleVersion.current().compareTo(GradleVersion.version("8.3")) < 0) {
    throw new GradleException("Use Gradle 8.3+ to avoid reflective setFileMode fallback.")
}

Prevention

When it happens

Trigger: Running a Spring Boot Gradle task that applies file permissions to a CopySpec (e.g. bootJar, bootDistZip, startScripts) on a Gradle version that routes through configureFileMode (below 8.3) but whose CopySpec implementation does not expose a setFileMode(Integer) method. This can happen on unusual Gradle distributions or when a third-party plugin replaces the CopySpec implementation.

Common situations: Using a very old or non-standard Gradle version (< 8.3) where the reflective method signature has changed or been removed. Using a Gradle fork or a custom CopySpec subclass that lacks setFileMode. Running against a Gradle version where the method exists but throws internally (e.g. permissions already locked).

Related errors


AI-assisted analysis of spring-projects/spring-boot@270dfe353f (2026-08-11). Data as JSON: /api/errors/37b12cbb42d59a91. Report an issue: GitHub.

Appendix: source

Thrown at build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ApplicationPluginAction.java:149

		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);
		}
	}

	private void configureFileMode(CopySpec copySpec, int mode) {
		try {
			copySpec.getClass().getMethod("setFileMode", Integer.class).invoke(copySpec, Integer.valueOf(mode));
		}
		catch (Exception ex) {
			throw new RuntimeException("Failed to set file mode on CopySpec", ex);
		}
	}

}

View on GitHub (pinned to 270dfe353f)