{"record":{"id":"37b12cbb42d59a91","repo":"spring-projects/spring-boot","slug":"failed-to-set-file-mode-on-copyspec","errorCode":null,"errorMessage":"Failed to set file mode on CopySpec","messagePattern":"Failed to set file mode on CopySpec","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ApplicationPluginAction.java","lineNumber":149,"sourceCode":"\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\n\tprivate void configureFileMode(CopySpec copySpec, int mode) {\n\t\ttry {\n\t\t\tcopySpec.getClass().getMethod(\"setFileMode\", Integer.class).invoke(copySpec, Integer.valueOf(mode));\n\t\t}\n\t\tcatch (Exception ex) {\n\t\t\tthrow new RuntimeException(\"Failed to set file mode on CopySpec\", ex);\n\t\t}\n\t}\n\n}\n","sourceCodeStart":131,"sourceCodeEnd":154,"githubUrl":"https://github.com/spring-projects/spring-boot/blob/270dfe353fb830fd69b823a8a859287ff103854b/build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/ApplicationPluginAction.java#L131-L154","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Upgrade Gradle to 8.3 or later, which uses the modern filePermissions API and avoids this reflective path entirely.","If you must stay on an older Gradle, ensure no custom CopySpec implementation overrides the default Gradle API surface.","Check for conflicting plugins that replace or wrap CopySpec types and remove or update them."],"exampleFix":"// before: running on Gradle 7.x with spring-boot-gradle-plugin\n// Upgrade gradle-wrapper.properties\ndistributionUrl=https\\://services.gradle.org/distributions/gradle-8.14-bin.zip\n// after: Gradle 8.14+ uses filePermissions() directly, never hits configureFileMode reflection","handlingStrategy":"validation","validationCode":"// In settings.gradle or build.gradle, gate the plugin on Gradle version before apply.\nif (GradleVersion.current().compareTo(GradleVersion.version(\"8.3\")) < 0) {\n    throw new GradleException(\"Use Gradle 8.3+ to avoid reflective setFileMode fallback.\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Standardize on Gradle 8.3+ (preferably the plugin's required minimum, 8.14) in the wrapper.","Do not replace the standard CopySpec with a custom subclass.","Keep the Gradle wrapper version and the Spring Boot plugin version aligned per the compatibility matrix."],"tags":["gradle","reflection","file-permissions","version-compat","copy-spec"],"backgroundTag":null,"analyzedSha":"270dfe353fb830fd69b823a8a859287ff103854b","analyzedAt":"2026-08-11T19:42:06.541Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}