Skip to content

Commit a8ab1c1

Browse files
gdecasonedtwigg
authored andcommitted
Makes check enforcement configurable
1 parent 0b20cd0 commit a8ab1c1

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessExtension.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,23 @@ public void removeFormat(String name) {
104104
}
105105
}
106106

107+
boolean enforceCheck = true;
108+
109+
/** Returns `true` if Gradle's `check` task should run `spotlessCheck`; `false` otherwise. */
110+
public boolean isEnforceCheck() {
111+
return enforceCheck;
112+
}
113+
114+
/**
115+
* Configures Gradle's `check` task to run `spotlessCheck` if `true`,
116+
* but to not do so if `false`.
117+
*
118+
* `true` by default.
119+
*/
120+
public void setEnforceCheck(boolean enforceCheck) {
121+
this.enforceCheck = enforceCheck;
122+
}
123+
107124
private <T extends FormatExtension> void configure(String name, Class<T> clazz, Action<T> configure) {
108125
T value = maybeCreate(name, clazz);
109126
configure.execute(value);

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessPlugin.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,11 @@ public Object doCall(TaskExecutionGraph graph) {
103103
// Add our check task as a dependency on the global check task
104104
// getTasks() returns a "live" collection, so this works even if the
105105
// task doesn't exist at the time this call is made
106-
project.getTasks()
107-
.matching(task -> task.getName().equals(JavaBasePlugin.CHECK_TASK_NAME))
108-
.all(task -> task.dependsOn(rootCheckTask));
106+
if (spotlessExtension.enforceCheck) {
107+
project.getTasks()
108+
.matching(task -> task.getName().equals(JavaBasePlugin.CHECK_TASK_NAME))
109+
.all(task -> task.dependsOn(rootCheckTask));
110+
}
109111

110112
// clear spotless' cache when the user does a clean
111113
project.getTasks()

0 commit comments

Comments
 (0)