You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2025/06/16 20:18:43 UTC

(lucene) branch main updated: Allow turning off gradle/groovy script spotless pass using 'lucene.spotlessGradleScripts' build option (#14791)

This is an automated email from the ASF dual-hosted git repository.

dweiss pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/main by this push:
     new 9238ca74a12 Allow turning off gradle/groovy script spotless pass using 'lucene.spotlessGradleScripts' build option (#14791)
9238ca74a12 is described below

commit 9238ca74a12f65aeafc5e0d136a097a294c72207
Author: Dawid Weiss <da...@carrotsearch.com>
AuthorDate: Mon Jun 16 22:18:38 2025 +0200

    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.
---
 .../lucene.validation.spotless-groovy.gradle       | 44 ++++++++++++++++------
 .../plugins/help/BuildOptionGroupsPlugin.java      |  1 +
 help/formatting.txt                                | 11 ++++++
 3 files changed, 45 insertions(+), 11 deletions(-)

diff --git a/build-tools/build-infra/src/main/groovy/lucene.validation.spotless-groovy.gradle b/build-tools/build-infra/src/main/groovy/lucene.validation.spotless-groovy.gradle
index 664650dfb1c..e5c5132c956 100644
--- a/build-tools/build-infra/src/main/groovy/lucene.validation.spotless-groovy.gradle
+++ b/build-tools/build-infra/src/main/groovy/lucene.validation.spotless-groovy.gradle
@@ -27,17 +27,39 @@ if (project != project.rootProject) {
 
 plugins.apply(SpotlessPlugin.class)
 
-spotless.format("gradleScripts", GroovyGradleExtension.class, { ext ->
-  ext.greclipse()
-  ext.leadingTabsToSpaces(2)
-  ext.trimTrailingWhitespace()
-  ext.endWithNewline()
-  ext.target([
-    "build-tools/**/*.gradle",
-    "build-tools/**/*.groovy",
-    "**/build.gradle"
-  ])
-})
+def spotlessGradleScriptsOptionName = "lucene.spotlessGradleScripts"
+Provider<Boolean> spotlessGradleScriptsOption = buildOptions.addBooleanOption(spotlessGradleScriptsOptionName,
+    "Enable formatting and validation of groovy/gradle scripts (you may want to turn it off locally on slow" +
+    " networks or computers)", true)
+
+if (!spotlessGradleScriptsOption.get()) {
+  // register empty stubs for the corresponding set of spotless tasks.
+  [
+    "spotlessGradleScripts",
+    "spotlessGradleScriptsApply",
+    "spotlessGradleScriptsCheck"
+  ].each {taskName ->
+    tasks.register(taskName, {
+      doFirst {
+        logger.warn("You requested spotless to be locally turned off for gradle/groovy scripts. CI " +
+            "checks may not pass if you have formatting " +
+            "differences ('${spotlessGradleScriptsOptionName}' build option is set to false).")
+      }
+    })
+  }
+} else {
+  spotless.format("gradleScripts", GroovyGradleExtension.class, { ext ->
+    ext.greclipse()
+    ext.leadingTabsToSpaces(2)
+    ext.trimTrailingWhitespace()
+    ext.endWithNewline()
+    ext.target([
+      "build-tools/**/*.gradle",
+      "build-tools/**/*.groovy",
+      "**/build.gradle"
+    ])
+  })
+}
 
 tasks.named("spotlessGradleScripts").configure {
   mustRunAfter ":lucene:build-tools:missing-doclet:spotlessJava"
diff --git a/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/help/BuildOptionGroupsPlugin.java b/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/help/BuildOptionGroupsPlugin.java
index 78d488c501e..444fbe196d7 100644
--- a/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/help/BuildOptionGroupsPlugin.java
+++ b/build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/help/BuildOptionGroupsPlugin.java
@@ -58,6 +58,7 @@ public class BuildOptionGroupsPlugin implements Plugin<Project> {
                     optionGroups.group(
                         "Build control and information",
                         explicitList(
+                            "lucene.spotlessGradleScripts",
                             "task.times",
                             "javac.failOnWarnings",
                             "tests.slowestSuites",
diff --git a/help/formatting.txt b/help/formatting.txt
index 5b18c9fbe73..137d371efea 100644
--- a/help/formatting.txt
+++ b/help/formatting.txt
@@ -18,3 +18,14 @@ majority of cases the formatter will do a great job of cleaning up the
 code. Occasionally you may want to rewrite the code (introduce a local
 variable or reshape code paths) so that it's easier to read after
 automatic formatting.
+
+Gradle scripts
+==============
+
+Groovy and gradle code is also automatically formatted and this formatting
+is enforced. This is unfortunately a heavy download and runtime-costly
+application. If you'd like to temporarily skip this validation step, set
+the lucene.spotlessGradleScripts option to false - either on command line
+using -Plucene.spotlessGradleScripts=false, in your local
+build-options.local.properties or by any other means build options can be
+set.
\ No newline at end of file