From 93ebfca7b8142c17458b9e58b6dda256c2c68275 Mon Sep 17 00:00:00 2001 From: Josh Cummings Date: Wed, 25 Sep 2024 13:30:50 -0600 Subject: [PATCH] Make Javaformat and AOT work together Spring JavaFormat seems to process all source directories, including those that contain AOT-generated sources. This causes failures for checkFormat as well as checkstyle. These are failures that we can ignore since the source code is generated. Additionally, there is some kind of interaction between JavaFormat and the Spring Boot AOT support that makes Gradle think that compileJava and a few other tasks need to depend on formatMain and formatTest. --- build.gradle | 21 ++++++++++++++++++- .../spring-boot/java/aot/data/build.gradle | 20 +++++++++++------- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index dc644f1..6c03509 100644 --- a/build.gradle +++ b/build.gradle @@ -26,9 +26,29 @@ allprojects { options.compilerArgs.add("-parameters") } + tasks.matching { it.name == 'formatAot' }.all { task -> + task.enabled = false + } + + tasks.matching { it.name == 'formatAotTest' }.all { task -> + task.enabled = false + } + tasks.matching { it.name == 'checkFormatAot' }.all { task -> task.enabled = false } + + tasks.matching { it.name == 'checkFormatAotTest' }.all { task -> + task.enabled = false + } + + tasks.matching { it.name == "checkstyleAot" }.all { task -> + task.enabled = false + } + + tasks.matching { it.name == "checkstyleAotTest" }.all { task -> + task.enabled = false + } } if (hasProperty('buildScan')) { @@ -51,4 +71,3 @@ tasks.register('runAllTests') { allTestsTasks } } - diff --git a/servlet/spring-boot/java/aot/data/build.gradle b/servlet/spring-boot/java/aot/data/build.gradle index 090bb34..19d4344 100644 --- a/servlet/spring-boot/java/aot/data/build.gradle +++ b/servlet/spring-boot/java/aot/data/build.gradle @@ -40,11 +40,17 @@ tasks.withType(Test).configureEach { outputs.upToDateWhen { false } } -compileJava { - dependsOn("formatMain") +if (plugins.hasPlugin("io.spring.javaformat")) { + compileJava { + dependsOn("formatMain") + } + tasks.checkFormatMain { + dependsOn("formatMain") + } + compileTestJava { + dependsOn("formatTest") + } + tasks.checkFormatTest { + dependsOn("formatTest") + } } - -compileTestJava { - dependsOn("formatTest") -} -