From 337623658e131b5010bf3d1a9e62a2bd0424540a Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Thu, 25 Jan 2018 18:59:19 -0500 Subject: [PATCH 1/3] Set Java 9 checkstyle to depend on checkstyle conf 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. --- .../gradle/precommit/PrecommitTasks.groovy | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy index c836f0bbcb167..11ec950368d17 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy @@ -130,27 +130,29 @@ class PrecommitTasks { } Task checkstyleTask = project.tasks.create('checkstyle') - // Apply the checkstyle plugin to create `checkstyleMain` and `checkstyleTest`. It only - // creates them if there is main or test code to check and it makes `check` depend - // on them. But we want `precommit` to depend on `checkstyle` which depends on them so - // we have to swap them. - project.pluginManager.apply('checkstyle') - project.checkstyle { - config = project.resources.text.fromFile(checkstyleConf, 'UTF-8') - configProperties = [ - suppressions: checkstyleSuppressions - ] - toolVersion = 7.5 - } - for (String taskName : ['checkstyleMain', 'checkstyleTest']) { - Task task = project.tasks.findByName(taskName) - if (task != null) { - project.tasks['check'].dependsOn.remove(task) - checkstyleTask.dependsOn(task) - task.dependsOn(copyCheckstyleConf) - task.inputs.file(checkstyleSuppressions) - task.reports { - html.enabled false + project.afterEvaluate { + // Apply the checkstyle plugin to create `checkstyleMain` and `checkstyleTest`. It only + // creates them if there is main or test code to check and it makes `check` depend + // on them. But we want `precommit` to depend on `checkstyle` which depends on them so + // we have to swap them. + project.pluginManager.apply('checkstyle') + project.checkstyle { + config = project.resources.text.fromFile(checkstyleConf, 'UTF-8') + configProperties = [ + suppressions: checkstyleSuppressions + ] + toolVersion = 7.5 + } + for (String taskName : ['checkstyleMain', 'checkstyleJava9', 'checkstyleTest']) { + Task task = project.tasks.findByName(taskName) + if (task != null) { + project.tasks['check'].dependsOn.remove(task) + checkstyleTask.dependsOn(task) + task.dependsOn(copyCheckstyleConf) + task.inputs.file(checkstyleSuppressions) + task.reports { + html.enabled false + } } } } From 503839cae98af25802fa70d961b97a75fea9ee03 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 20 Mar 2018 07:49:31 -0400 Subject: [PATCH 2/3] Iteration --- .../gradle/precommit/PrecommitTasks.groovy | 51 ++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy index 11ec950368d17..7aeb6e53c76b6 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy +++ b/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. @@ -130,32 +131,36 @@ class PrecommitTasks { } Task checkstyleTask = project.tasks.create('checkstyle') - project.afterEvaluate { - // Apply the checkstyle plugin to create `checkstyleMain` and `checkstyleTest`. It only - // creates them if there is main or test code to check and it makes `check` depend - // on them. But we want `precommit` to depend on `checkstyle` which depends on them so - // we have to swap them. - project.pluginManager.apply('checkstyle') - project.checkstyle { - config = project.resources.text.fromFile(checkstyleConf, 'UTF-8') - configProperties = [ - suppressions: checkstyleSuppressions - ] - toolVersion = 7.5 - } - for (String taskName : ['checkstyleMain', 'checkstyleJava9', 'checkstyleTest']) { - Task task = project.tasks.findByName(taskName) - if (task != null) { - project.tasks['check'].dependsOn.remove(task) - checkstyleTask.dependsOn(task) - task.dependsOn(copyCheckstyleConf) - task.inputs.file(checkstyleSuppressions) - task.reports { - html.enabled false - } + + // Apply the checkstyle plugin to create `checkstyleMain` and `checkstyleTest`. It only + // creates them if there is main or test code to check and it makes `check` depend + // on them. But we want `precommit` to depend on `checkstyle` which depends on them so + // we have to swap them. + project.pluginManager.apply('checkstyle') + project.checkstyle { + config = project.resources.text.fromFile(checkstyleConf, 'UTF-8') + configProperties = [ + suppressions: checkstyleSuppressions + ] + toolVersion = 7.5 + } + for (String taskName : ['checkstyleMain', 'checkstyleJava9', 'checkstyleTest']) { + Task task = project.tasks.findByName(taskName) + if (task != null) { + project.tasks['check'].dependsOn.remove(task) + checkstyleTask.dependsOn(task) + task.dependsOn(copyCheckstyleConf) + task.inputs.file(checkstyleSuppressions) + task.reports { + html.enabled false } } } + + project.tasks.withType(Checkstyle) { + dependsOn(copyCheckstyleConf) + } + return checkstyleTask } From 8d6544acad1e03b39d4db7c7418cf49b1a76fb07 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 20 Mar 2018 07:51:44 -0400 Subject: [PATCH 3/3] Remove formatting changes --- .../org/elasticsearch/gradle/precommit/PrecommitTasks.groovy | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy index 7aeb6e53c76b6..9e1cdad04fd6c 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy @@ -131,7 +131,6 @@ class PrecommitTasks { } Task checkstyleTask = project.tasks.create('checkstyle') - // Apply the checkstyle plugin to create `checkstyleMain` and `checkstyleTest`. It only // creates them if there is main or test code to check and it makes `check` depend // on them. But we want `precommit` to depend on `checkstyle` which depends on them so @@ -140,7 +139,7 @@ class PrecommitTasks { project.checkstyle { config = project.resources.text.fromFile(checkstyleConf, 'UTF-8') configProperties = [ - suppressions: checkstyleSuppressions + suppressions: checkstyleSuppressions ] toolVersion = 7.5 }