Skip to content

Commit 025dbdc

Browse files
authored
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.
1 parent d95bca8 commit 025dbdc

File tree

2 files changed

+3
-16
lines changed

2 files changed

+3
-16
lines changed

build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/precommit/FormattingPrecommitPlugin.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
import org.gradle.api.Plugin;
1515
import org.gradle.api.Project;
1616

17-
import java.util.List;
18-
1917
/**
2018
* This plugin configures formatting for Java source using Spotless
2119
* for Gradle. Since the act of formatting existing source can interfere
@@ -43,10 +41,7 @@ public class FormattingPrecommitPlugin implements Plugin<Project> {
4341

4442
@Override
4543
public void apply(Project project) {
46-
final boolean shouldFormatProject = PROJECT_PATHS_TO_EXCLUDE.contains(project.getPath()) == false
47-
|| project.getProviders().systemProperty("es.format.everything").forUseAtConfigurationTime().isPresent();
48-
49-
if (shouldFormatProject) {
44+
project.getPluginManager().withPlugin("java-base", javaBasePlugin -> {
5045
project.getPlugins().apply(PrecommitTaskPlugin.class);
5146
project.getPlugins().apply(SpotlessPlugin.class);
5247

@@ -83,14 +78,6 @@ public void apply(Project project) {
8378
});
8479

8580
project.getTasks().named("precommit").configure(precommitTask -> precommitTask.dependsOn("spotlessJavaCheck"));
86-
}
81+
});
8782
}
88-
89-
// Do not add new sub-projects here!
90-
private static final List<String> PROJECT_PATHS_TO_EXCLUDE = List.of(
91-
":distribution:bwc:bugfix",
92-
":distribution:bwc:maintenance",
93-
":distribution:bwc:minor",
94-
":distribution:bwc:staged"
95-
);
9683
}

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ tasks.register("buildReleaseArtifacts").configure {
430430
.findAll { it != null }
431431
}
432432

433-
tasks.named("spotlessApply").configure {
433+
tasks.register("spotlessApply").configure {
434434
dependsOn gradle.includedBuild('build-tools').task(':spotlessApply')
435435
dependsOn gradle.includedBuild('build-tools').task(':reaper:spotlessApply')
436436
dependsOn gradle.includedBuild('build-tools-internal').task(':spotlessApply')

0 commit comments

Comments
 (0)