From c1169418c9dcda57f5613bec44d1838a788d3683 Mon Sep 17 00:00:00 2001 From: Guido de Caso Date: Fri, 31 Mar 2017 20:28:10 -0300 Subject: [PATCH] Makes check enforcement configurable --- .../gradle/spotless/SpotlessExtension.java | 3 +++ .../gradle/spotless/SpotlessPlugin.java | 20 +++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java index 66e32a88cc..be1262078b 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java @@ -104,6 +104,9 @@ public void removeFormat(String name) { } } + /** Allows configuring whether the check {@link SpotlessTask} should be enforced when performing builds or not. */ + public boolean enforceCheck = true; + private void configure(String name, Class clazz, Action configure) { T value = maybeCreate(name, clazz); configure.execute(value); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java index 54e6008ee0..e1b34eecb4 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java @@ -15,19 +15,17 @@ */ package com.diffplug.gradle.spotless; -import java.util.Map; - +import com.diffplug.common.base.Errors; +import com.diffplug.spotless.SpotlessCache; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import groovy.lang.Closure; import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.Task; import org.gradle.api.execution.TaskExecutionGraph; import org.gradle.api.plugins.JavaBasePlugin; -import com.diffplug.common.base.Errors; -import com.diffplug.spotless.SpotlessCache; - -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import groovy.lang.Closure; +import java.util.Map; public class SpotlessPlugin implements Plugin { Project project; @@ -103,9 +101,11 @@ public Object doCall(TaskExecutionGraph graph) { // Add our check task as a dependency on the global check task // getTasks() returns a "live" collection, so this works even if the // task doesn't exist at the time this call is made - project.getTasks() - .matching(task -> task.getName().equals(JavaBasePlugin.CHECK_TASK_NAME)) - .all(task -> task.dependsOn(rootCheckTask)); + if (spotlessExtension.enforceCheck) { + project.getTasks() + .matching(task -> task.getName().equals(JavaBasePlugin.CHECK_TASK_NAME)) + .all(task -> task.dependsOn(rootCheckTask)); + } // clear spotless' cache when the user does a clean project.getTasks()