diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/PrecommitPlugin.java b/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/PrecommitPlugin.java index b5b20c305ce66..8333c676cadda 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/PrecommitPlugin.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/PrecommitPlugin.java @@ -12,7 +12,6 @@ import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.Task; -import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.TaskProvider; /** @@ -34,9 +33,8 @@ public final void apply(Project project) { "java", p -> { // We want to get any compilation error before running the pre-commit checks. - for (SourceSet sourceSet : GradleUtils.getJavaSourceSets(project)) { - task.configure(t -> t.shouldRunAfter(sourceSet.getClassesTaskName())); - } + GradleUtils.getJavaSourceSets(project) + .all(sourceSet -> task.configure(t -> t.shouldRunAfter(sourceSet.getClassesTaskName()))); } ); } diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/PrecommitTaskPlugin.java b/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/PrecommitTaskPlugin.java index 2599016c15390..8051822457439 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/PrecommitTaskPlugin.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/PrecommitTaskPlugin.java @@ -13,7 +13,6 @@ import org.gradle.api.Project; import org.gradle.api.Task; import org.gradle.api.plugins.JavaBasePlugin; -import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.TaskProvider; import org.gradle.api.tasks.testing.Test; import org.gradle.language.base.plugins.LifecycleBasePlugin; @@ -37,9 +36,8 @@ public void apply(Project project) { "java", p -> { // run compilation as part of precommit - for (SourceSet sourceSet : GradleUtils.getJavaSourceSets(project)) { - precommit.configure(t -> t.dependsOn(sourceSet.getClassesTaskName())); - } + GradleUtils.getJavaSourceSets(project) + .all(sourceSet -> precommit.configure(t -> t.dependsOn(sourceSet.getClassesTaskName()))); // make sure tests run after all precommit tasks project.getTasks().withType(Test.class).configureEach(t -> t.mustRunAfter(precommit));