diff --git a/.github/workflows/beam_PreCommit_Spotless.yml b/.github/workflows/beam_PreCommit_Spotless.yml index 64701930e856..d698e7c96878 100644 --- a/.github/workflows/beam_PreCommit_Spotless.yml +++ b/.github/workflows/beam_PreCommit_Spotless.yml @@ -85,11 +85,13 @@ jobs: github_job: ${{ matrix.job_name }} (${{ matrix.job_phrase }}) - name: Setup environment uses: ./.github/actions/setup-environment-action + - name: Fetch origin/master for Spotless ratcheting + run: git fetch origin master:refs/remotes/origin/master - name: run Spotless PreCommit script uses: ./.github/actions/gradle-command-self-hosted-action with: gradle-command: spotlessCheck checkStyleMain checkStyleTest :buildSrc:spotlessCheck - arguments: -PdisableSpotlessApply + arguments: -PdisableSpotlessApply -PspotlessRatchet - name: Upload test report uses: actions/upload-artifact@v7 with: diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 96b1cb12dd4c..ad75eff8f6b1 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -32,7 +32,7 @@ val useMirror = isCi && !mavenCentralMirrorUrl.isNullOrBlank() plugins { `java-gradle-plugin` groovy - id("com.diffplug.spotless") version "5.6.1" + id("com.diffplug.spotless") version "7.2.1" } // Define the set of repositories required to fetch and enable plugins. @@ -68,7 +68,7 @@ dependencies { runtimeOnly("com.google.protobuf:protobuf-gradle-plugin:0.8.13") // Enable proto code generation runtimeOnly("com.github.davidmc24.gradle.plugin:gradle-avro-plugin:1.9.1") // Enable Avro code generation. Version 1.1.0 is the last supporting avro 1.10.2 - runtimeOnly("com.diffplug.spotless:spotless-plugin-gradle:5.6.1") // Enable a code formatting plugin + runtimeOnly("com.diffplug.spotless:spotless-plugin-gradle:7.2.1") // Enable a code formatting plugin runtimeOnly("gradle.plugin.com.dorongold.plugins:task-tree:1.5") // Adds a 'taskTree' task to print task dependency tree runtimeOnly("net.linguica.gradle:maven-settings-plugin:0.5") runtimeOnly("gradle.plugin.io.pry.gradle.offline_dependencies:gradle-offline-dependencies-plugin:0.5.0") // Enable creating an offline repository diff --git a/buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy b/buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy index 8298eacff4d2..5dd5579cd2de 100644 --- a/buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy +++ b/buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy @@ -1176,16 +1176,16 @@ class BeamModulePlugin implements Plugin { // If compiled on older SDK, compile with JDK configured with compatible javaXXHome // The order is intended here if (requireJavaVersion.compareTo(JavaVersion.VERSION_11) <= 0 && - project.findProperty('java11Home')) { + project.findProperty('java11Home')) { forkJavaVersion = '11' } else if (requireJavaVersion.compareTo(JavaVersion.VERSION_17) <= 0 && - project.findProperty('java17Home')) { + project.findProperty('java17Home')) { forkJavaVersion = '17' } else if (requireJavaVersion.compareTo(JavaVersion.VERSION_21) <= 0 && - project.findProperty('java21Home')) { + project.findProperty('java21Home')) { forkJavaVersion = '21' } else if (requireJavaVersion.compareTo(JavaVersion.VERSION_25) <= 0 && - project.findProperty('java25Home')) { + project.findProperty('java25Home')) { forkJavaVersion = '25' } else { logger.config("Module ${project.name} disabled. To enable, either " + @@ -1455,6 +1455,12 @@ class BeamModulePlugin implements Plugin { // command-line. This is useful for pre-commit which runs checkStyle separately. def disableCheckStyle = project.hasProperty('disableCheckStyle') && project.disableCheckStyle == 'true' + project.tasks.withType(org.gradle.api.plugins.quality.Checkstyle).configureEach { + classpath = project.files() + exclude '**/generated-src/**' + exclude '**/generated-sources/**' + mustRunAfter project.tasks.matching { it.name.startsWith('generate') } + } project.checkstyleMain.enabled = !disableCheckStyle project.checkstyleTest.enabled = !disableCheckStyle @@ -1476,12 +1482,16 @@ class BeamModulePlugin implements Plugin { project.disableSpotlessCheck == 'true' project.spotless { enforceCheck !disableSpotlessCheck + if (project.hasProperty('spotlessRatchet')) { + ratchetFrom project.findProperty('spotlessRatchetFrom') ?: 'origin/master' + } java { licenseHeader javaLicenseHeader - googleJavaFormat('1.7') + googleJavaFormat('1.17.0') target project.fileTree(project.projectDir) { include 'src/*/java/**/*.java' exclude '**/DefaultPackageTest.java' + exclude '**/module-info.java' } // For spotless:off and spotless:on toggleOffOn() @@ -2098,7 +2108,8 @@ class BeamModulePlugin implements Plugin { } else { dependencyNode.appendNode('groupId', it.group) dependencyNode.appendNode('artifactId', it.name) - if (it.version != null) { // bom-managed artifacts do not have their versions + if (it.version != null) { + // bom-managed artifacts do not have their versions dependencyNode.appendNode('version', it.version) } dependencyNode.appendNode('scope', param.scope) @@ -2465,7 +2476,8 @@ class BeamModulePlugin implements Plugin { project.protobuf { protoc { // The artifact spec for the Protobuf Compiler - artifact = "com.google.protobuf:protoc:$protobuf_version" } + artifact = "com.google.protobuf:protoc:$protobuf_version" + } // Configure the codegen plugins plugins { @@ -2547,7 +2559,8 @@ class BeamModulePlugin implements Plugin { project.protobuf { protoc { // The artifact spec for the Protobuf Compiler - artifact = "com.google.protobuf:protoc:${GrpcVendoring_1_69_0.protobuf_version}" } + artifact = "com.google.protobuf:protoc:${GrpcVendoring_1_69_0.protobuf_version}" + } // Configure the codegen plugins plugins { @@ -2745,7 +2758,8 @@ class BeamModulePlugin implements Plugin { doLast { def beamPythonTestPipelineOptions = [ "pipeline_opts": config.pythonPipelineOptions + (usesDataflowRunner ? [ - "--sdk_location=${project.ext.sdkLocation}"] + "--sdk_location=${project.ext.sdkLocation}" + ] : []), "test_opts": config.pytestOptions, "suite": config.name, @@ -3037,7 +3051,8 @@ class BeamModulePlugin implements Plugin { doLast { def beamPythonTestPipelineOptions = [ "pipeline_opts": config.pythonPipelineOptions + (usesDataflowRunner ? [ - "--sdk_location=${project.ext.sdkLocation}"] + "--sdk_location=${project.ext.sdkLocation}" + ] : []), "test_opts": config.pytestOptions, "suite": config.name, diff --git a/runners/flink/build.gradle b/runners/flink/build.gradle index 4d058a481820..d7fcd072fdd3 100644 --- a/runners/flink/build.gradle +++ b/runners/flink/build.gradle @@ -23,10 +23,17 @@ apply plugin: 'com.diffplug.spotless' * These java sources are included in the subproject's sources in order to compile against the different versions. * We configure spotless here once in order to only check these java sources once. */ +repositories { + mavenCentral() +} + spotless { + if (project.hasProperty('spotlessRatchet')) { + ratchetFrom project.findProperty('spotlessRatchetFrom') ?: 'origin/master' + } java { licenseHeader org.apache.beam.gradle.BeamModulePlugin.javaLicenseHeader - googleJavaFormat('1.7') + googleJavaFormat('1.17.0') target project.fileTree(project.projectDir) { include 'src/*/java/**/*.java' } } } \ No newline at end of file diff --git a/runners/spark/build.gradle b/runners/spark/build.gradle index 4d058a481820..d7fcd072fdd3 100644 --- a/runners/spark/build.gradle +++ b/runners/spark/build.gradle @@ -23,10 +23,17 @@ apply plugin: 'com.diffplug.spotless' * These java sources are included in the subproject's sources in order to compile against the different versions. * We configure spotless here once in order to only check these java sources once. */ +repositories { + mavenCentral() +} + spotless { + if (project.hasProperty('spotlessRatchet')) { + ratchetFrom project.findProperty('spotlessRatchetFrom') ?: 'origin/master' + } java { licenseHeader org.apache.beam.gradle.BeamModulePlugin.javaLicenseHeader - googleJavaFormat('1.7') + googleJavaFormat('1.17.0') target project.fileTree(project.projectDir) { include 'src/*/java/**/*.java' } } } \ No newline at end of file diff --git a/sdks/java/io/cassandra/build.gradle b/sdks/java/io/cassandra/build.gradle index 43ac8bc8bf85..402490c3309c 100644 --- a/sdks/java/io/cassandra/build.gradle +++ b/sdks/java/io/cassandra/build.gradle @@ -62,7 +62,7 @@ dependencies { configurations.all (Configuration it) -> { // error-prone requires newer guava, don't override for annotation processing // https://github.com/google/error-prone/issues/2745 - if (it.name == "annotationProcessor" || it.name =="testAnnotationProcessor") { + if (it.name == "annotationProcessor" || it.name =="testAnnotationProcessor" || it.name.startsWith("spotless")) { return } resolutionStrategy { diff --git a/sdks/java/io/hadoop-file-system/build.gradle b/sdks/java/io/hadoop-file-system/build.gradle index d78d6a300cac..854ccefa0174 100644 --- a/sdks/java/io/hadoop-file-system/build.gradle +++ b/sdks/java/io/hadoop-file-system/build.gradle @@ -85,7 +85,7 @@ hadoopVersions.each {kv -> configurations.all (Configuration it) -> { // error-prone requires newer guava, don't override for annotation processing // https://github.com/google/error-prone/issues/2745 - if (it.name == "annotationProcessor" || it.name =="testAnnotationProcessor") { + if (it.name == "annotationProcessor" || it.name =="testAnnotationProcessor" || it.name.startsWith("spotless")) { return } resolutionStrategy { diff --git a/sdks/java/io/hadoop-format/build.gradle b/sdks/java/io/hadoop-format/build.gradle index 83dfcf22d86d..92eda09a3166 100644 --- a/sdks/java/io/hadoop-format/build.gradle +++ b/sdks/java/io/hadoop-format/build.gradle @@ -125,7 +125,7 @@ hadoopVersions.each {kv -> configurations.all (Configuration it) -> { // error-prone requires newer guava, don't override for annotation processing // https://github.com/google/error-prone/issues/2745 - if (it.name == "annotationProcessor" || it.name =="testAnnotationProcessor") { + if (it.name == "annotationProcessor" || it.name =="testAnnotationProcessor" || it.name.startsWith("spotless")) { return } resolutionStrategy {