diff --git a/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java b/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java
index f366afd2839..6e5e79b10b2 100644
--- a/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java
+++ b/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java
@@ -31,6 +31,7 @@ import java.util.TreeMap;
import java.util.function.Consumer;
import java.util.stream.Collectors;
+import io.spring.javaformat.gradle.CheckTask;
import io.spring.javaformat.gradle.FormatTask;
import io.spring.javaformat.gradle.SpringJavaFormatPlugin;
import org.gradle.api.Action;
@@ -43,6 +44,7 @@ import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.DependencySet;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.plugins.JavaPlugin;
+import org.gradle.api.plugins.quality.Checkstyle;
import org.gradle.api.plugins.quality.CheckstyleExtension;
import org.gradle.api.plugins.quality.CheckstylePlugin;
import org.gradle.api.tasks.SourceSet;
@@ -66,7 +68,12 @@ import org.springframework.boot.build.testing.TestFailuresPlugin;
*
{@link SpringJavaFormatPlugin Spring Java Format}, {@link CheckstylePlugin
* Checkstyle}, {@link TestFailuresPlugin Test Failures}, and {@link TestRetryPlugin Test
* Retry} plugins are applied
- * {@link Test} tasks are configured to use JUnit Platform and use a max heap of 1024M
+ * {@link Test} tasks are configured:
+ *
+ * - to use JUnit Platform
+ *
- with a max heap of 1024M
+ *
- to run after any Checkstyle and format checking tasks
+ *
* A {@code testRuntimeOnly} dependency upon
* {@code org.junit.platform:junit-platform-launcher} is added to projects with the
* {@link JavaPlugin} applied
@@ -156,6 +163,8 @@ class JavaConventions {
"file:" + test.getWorkingDir().toPath().relativize(copyJdk8156584SecurityProperties.output));
test.doFirst(copyJdk8156584SecurityProperties);
}
+ project.getTasks().withType(Checkstyle.class, (checkstyle) -> test.mustRunAfter(checkstyle));
+ project.getTasks().withType(CheckTask.class, (checkFormat) -> test.mustRunAfter(checkFormat));
});
project.getPlugins().withType(JavaPlugin.class, (javaPlugin) -> project.getDependencies()
.add(JavaPlugin.TEST_RUNTIME_ONLY_CONFIGURATION_NAME, "org.junit.platform:junit-platform-launcher"));