From 025dbdc73e228c71025ae599bec2bbf12e1720fe Mon Sep 17 00:00:00 2001 From: Mark Vieira Date: Thu, 11 Nov 2021 15:17:10 -0800 Subject: [PATCH] Don't apply the spotless plugin to non-applicable projects (#80679) This is an attempt at resolving, or at least reducing the prevalence of #77837. A more robust solution is probably required, but this should help reduce this problem since we now apply spotless to about 90 fewer subprojects. --- .../precommit/FormattingPrecommitPlugin.java | 17 ++--------------- build.gradle | 2 +- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/precommit/FormattingPrecommitPlugin.java b/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/precommit/FormattingPrecommitPlugin.java index f106ad01b5212..17a845f166b10 100644 --- a/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/precommit/FormattingPrecommitPlugin.java +++ b/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/precommit/FormattingPrecommitPlugin.java @@ -14,8 +14,6 @@ import org.gradle.api.Plugin; import org.gradle.api.Project; -import java.util.List; - /** * This plugin configures formatting for Java source using Spotless * for Gradle. Since the act of formatting existing source can interfere @@ -43,10 +41,7 @@ public class FormattingPrecommitPlugin implements Plugin { @Override public void apply(Project project) { - final boolean shouldFormatProject = PROJECT_PATHS_TO_EXCLUDE.contains(project.getPath()) == false - || project.getProviders().systemProperty("es.format.everything").forUseAtConfigurationTime().isPresent(); - - if (shouldFormatProject) { + project.getPluginManager().withPlugin("java-base", javaBasePlugin -> { project.getPlugins().apply(PrecommitTaskPlugin.class); project.getPlugins().apply(SpotlessPlugin.class); @@ -83,14 +78,6 @@ public void apply(Project project) { }); project.getTasks().named("precommit").configure(precommitTask -> precommitTask.dependsOn("spotlessJavaCheck")); - } + }); } - - // Do not add new sub-projects here! - private static final List PROJECT_PATHS_TO_EXCLUDE = List.of( - ":distribution:bwc:bugfix", - ":distribution:bwc:maintenance", - ":distribution:bwc:minor", - ":distribution:bwc:staged" - ); } diff --git a/build.gradle b/build.gradle index cdcea74210e9b..59fc13e9e1ac8 100644 --- a/build.gradle +++ b/build.gradle @@ -430,7 +430,7 @@ tasks.register("buildReleaseArtifacts").configure { .findAll { it != null } } -tasks.named("spotlessApply").configure { +tasks.register("spotlessApply").configure { dependsOn gradle.includedBuild('build-tools').task(':spotlessApply') dependsOn gradle.includedBuild('build-tools').task(':reaper:spotlessApply') dependsOn gradle.includedBuild('build-tools-internal').task(':spotlessApply')