From 936998647e877d330cb6d36697f1632140ebdf3e Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 2 Mar 2022 20:26:15 +0000 Subject: [PATCH] Work around Gradle changing line endings during property expansion There's a known issue [1] where property expansion changes the input files line endings to the operating system's default. This causes problems for us on Windows as the line endings become \r\n which breaks our formatting checks. This commit tunes the checkFormatMain task to exclude the generated source files from checking. In their place, the original templates are added. This ensures that the inputs are correctly formatted and, therefore, that the output should be too (other than the line endings on Windows). Closes gh-30039 [1] https://github.com/gradle/gradle/issues/1151 --- spring-boot-project/spring-boot/build.gradle | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spring-boot-project/spring-boot/build.gradle b/spring-boot-project/spring-boot/build.gradle index 75050bf25b..1b679a0ab5 100644 --- a/spring-boot-project/spring-boot/build.gradle +++ b/spring-boot-project/spring-boot/build.gradle @@ -164,6 +164,14 @@ def syncJavaTemplates = tasks.register("syncJavaTemplates", Sync) { inputs.properties(properties) } +tasks.named("checkFormatMain") { + def generatedSources = fileTree("build/generated-sources/main") + // Exclude source generated from the templates as expand(properties) changes line endings on Windows + exclude { candidate -> generatedSources.contains(candidate.file) } + // Add the templates to check that the input is correctly formatted + source(fileTree("src/main/javaTemplates")) +} + plugins.withType(EclipsePlugin) { eclipse { synchronizationTasks syncJavaTemplates