Skip to content

Commit

Permalink
Don't apply the spotless plugin to non-applicable projects (#80679) (#…
Browse files Browse the repository at this point in the history
…80680)

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.
  • Loading branch information
mark-vieira committed Nov 12, 2021
1 parent d776a72 commit 5275147
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -43,10 +41,7 @@ public class FormattingPrecommitPlugin implements Plugin<Project> {

@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);

Expand Down Expand Up @@ -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<String> PROJECT_PATHS_TO_EXCLUDE = List.of(
":distribution:bwc:bugfix",
":distribution:bwc:maintenance",
":distribution:bwc:minor",
":distribution:bwc:staged"
);
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,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')
Expand Down

0 comments on commit 5275147

Please sign in to comment.