Skip to content

Commit 9238ca7

Browse files
authored
Allow turning off gradle/groovy script spotless pass using 'lucene.spotlessGradleScripts' build option (#14791)
* Allow turning off gradle/groovy script spotless pass using 'lucene.spotlessGradleScripts' build option. Fixes #14789 * Add this option to the build control group.
1 parent 436e21d commit 9238ca7

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed

build-tools/build-infra/src/main/groovy/lucene.validation.spotless-groovy.gradle

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,39 @@ if (project != project.rootProject) {
2727

2828
plugins.apply(SpotlessPlugin.class)
2929

30-
spotless.format("gradleScripts", GroovyGradleExtension.class, { ext ->
31-
ext.greclipse()
32-
ext.leadingTabsToSpaces(2)
33-
ext.trimTrailingWhitespace()
34-
ext.endWithNewline()
35-
ext.target([
36-
"build-tools/**/*.gradle",
37-
"build-tools/**/*.groovy",
38-
"**/build.gradle"
39-
])
40-
})
30+
def spotlessGradleScriptsOptionName = "lucene.spotlessGradleScripts"
31+
Provider<Boolean> spotlessGradleScriptsOption = buildOptions.addBooleanOption(spotlessGradleScriptsOptionName,
32+
"Enable formatting and validation of groovy/gradle scripts (you may want to turn it off locally on slow" +
33+
" networks or computers)", true)
34+
35+
if (!spotlessGradleScriptsOption.get()) {
36+
// register empty stubs for the corresponding set of spotless tasks.
37+
[
38+
"spotlessGradleScripts",
39+
"spotlessGradleScriptsApply",
40+
"spotlessGradleScriptsCheck"
41+
].each {taskName ->
42+
tasks.register(taskName, {
43+
doFirst {
44+
logger.warn("You requested spotless to be locally turned off for gradle/groovy scripts. CI " +
45+
"checks may not pass if you have formatting " +
46+
"differences ('${spotlessGradleScriptsOptionName}' build option is set to false).")
47+
}
48+
})
49+
}
50+
} else {
51+
spotless.format("gradleScripts", GroovyGradleExtension.class, { ext ->
52+
ext.greclipse()
53+
ext.leadingTabsToSpaces(2)
54+
ext.trimTrailingWhitespace()
55+
ext.endWithNewline()
56+
ext.target([
57+
"build-tools/**/*.gradle",
58+
"build-tools/**/*.groovy",
59+
"**/build.gradle"
60+
])
61+
})
62+
}
4163

4264
tasks.named("spotlessGradleScripts").configure {
4365
mustRunAfter ":lucene:build-tools:missing-doclet:spotlessJava"

build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/help/BuildOptionGroupsPlugin.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public void apply(Project project) {
5858
optionGroups.group(
5959
"Build control and information",
6060
explicitList(
61+
"lucene.spotlessGradleScripts",
6162
"task.times",
6263
"javac.failOnWarnings",
6364
"tests.slowestSuites",

help/formatting.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,14 @@ majority of cases the formatter will do a great job of cleaning up the
1818
code. Occasionally you may want to rewrite the code (introduce a local
1919
variable or reshape code paths) so that it's easier to read after
2020
automatic formatting.
21+
22+
Gradle scripts
23+
==============
24+
25+
Groovy and gradle code is also automatically formatted and this formatting
26+
is enforced. This is unfortunately a heavy download and runtime-costly
27+
application. If you'd like to temporarily skip this validation step, set
28+
the lucene.spotlessGradleScripts option to false - either on command line
29+
using -Plucene.spotlessGradleScripts=false, in your local
30+
build-options.local.properties or by any other means build options can be
31+
set.

0 commit comments

Comments
 (0)