Browse Source

Set Java 9 checkstyle to depend on checkstyle conf (#28383)

We need to configure the Java 9 checkstyle task to depend on the
checkstyle configuration task or the task could run before the
checkstyle conf has been copied leading to runtime failures. We have to
do this after projects have been evaluated because the configuration of
these tasks can occur before the Java 9 source set has been added to a
project.
Jason Tedor 7 years ago
parent
commit
d766b68f7a

+ 7 - 1
buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy

@@ -22,6 +22,7 @@ import de.thetaphi.forbiddenapis.gradle.ForbiddenApisPlugin
 import org.gradle.api.Project
 import org.gradle.api.Task
 import org.gradle.api.plugins.JavaBasePlugin
+import org.gradle.api.plugins.quality.Checkstyle
 
 /**
  * Validation tasks which should be run before committing. These run before tests.
@@ -142,7 +143,7 @@ class PrecommitTasks {
             ]
             toolVersion = 7.5
         }
-        for (String taskName : ['checkstyleMain', 'checkstyleTest']) {
+        for (String taskName : ['checkstyleMain', 'checkstyleJava9', 'checkstyleTest']) {
             Task task = project.tasks.findByName(taskName)
             if (task != null) {
                 project.tasks['check'].dependsOn.remove(task)
@@ -154,6 +155,11 @@ class PrecommitTasks {
                 }
             }
         }
+
+        project.tasks.withType(Checkstyle) {
+            dependsOn(copyCheckstyleConf)
+        }
+
         return checkstyleTask
     }