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

borinquenkid pushed a commit to branch 8.0.x-hibernate7
in repository https://gitbox.apache.org/repos/asf/grails-core.git

commit de8c2610c801633ec5565c34d683b5be8d4c3278
Author: Walter Duque de Estrada <[email protected]>
AuthorDate: Sun Mar 1 13:25:36 2026 -0600

    chore: replace Checkstyle with Spotless and add PMD globally
    
    - gradle/code-style-config.gradle:
      - Remove Checkstyle plugin/config; add Spotless (palantirJavaFormat,
        4-space indent) with import ordering matching the former Checkstyle
        ImportOrderCheck groups (java|javax → groovy → jakarta → other →
        spring → grails → static last), removeUnusedImports,
        trimTrailingWhitespace, endWithNewline
      - Add PMD plugin globally alongside CodeNarc; backed by a new
        etc/config/pmd/pmd.xml ruleset (bestpractices, errorprone, security)
      - codeStyle task now runs: Spotless check + CodeNarc + PMD
    
    - gradle.properties:
      - Replace checkstyleVersion with pmdVersion=6.55.0
    
    - etc/config/pmd/pmd.xml:
      - New PMD ruleset (category/java/bestpractices, errorprone, security)
    
    - grails-data-hibernate7/core/build.gradle:
      - Remove local pmd and spotless plugin declarations/config (now
        handled globally via code-style-config.gradle)
      - Apply code-style-config.gradle; keep SpotBugs local config
    
    Note: run ./gradlew spotlessApply to reformat existing Java sources to
    palantirJavaFormat before next code style check.
    
    Co-authored-by: Copilot <[email protected]>
---
 etc/config/pmd/pmd.xml                   | 31 ++++++++++++++++++++
 gradle.properties                        |  2 +-
 gradle/code-style-config.gradle          | 49 +++++++++++++++++++++++++-------
 grails-data-hibernate7/core/build.gradle | 32 ++-------------------
 4 files changed, 73 insertions(+), 41 deletions(-)

diff --git a/etc/config/pmd/pmd.xml b/etc/config/pmd/pmd.xml
new file mode 100644
index 0000000000..cf494a7125
--- /dev/null
+++ b/etc/config/pmd/pmd.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+<ruleset name="Grails PMD Rules"
+        xmlns="http://pmd.sourceforge.net/ruleset/2.0.0";
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+        xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 
https://pmd.sourceforge.io/ruleset_2_0_0.xsd";>
+
+    <description>PMD ruleset for the Grails codebase</description>
+
+    <rule ref="category/java/bestpractices.xml"/>
+    <rule ref="category/java/errorprone.xml"/>
+    <rule ref="category/java/security.xml"/>
+
+</ruleset>
diff --git a/gradle.properties b/gradle.properties
index e87a20b74e..1c4cb7424d 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -68,7 +68,7 @@ micronautHttpClientVersion=4.9.9
 micronautSerdeJacksonVersion=2.11.0
 
 # build dependencies for code quality checks
-checkstyleVersion=11.0.0
+pmdVersion=6.55.0
 codenarcVersion=3.6.0-groovy-4.0
 
 # This prevents the Grails Gradle Plugin from unnecessarily excluding 
slf4j-simple in the generated POMs
diff --git a/gradle/code-style-config.gradle b/gradle/code-style-config.gradle
index 9c3ad1f3c1..d7a74d652d 100644
--- a/gradle/code-style-config.gradle
+++ b/gradle/code-style-config.gradle
@@ -17,26 +17,46 @@
  *  under the License.
  */
 
-apply plugin: 'checkstyle'
+apply plugin: 'pmd'
 apply plugin: 'codenarc'
+apply plugin: 'com.diffplug.spotless'
 
-extensions.configure(CheckstyleExtension) {
-    // Explicit `it` is required in extension configuration
-    it.configDirectory = 
rootProject.layout.projectDirectory.dir('etc/config/checkstyle').asFile
-    it.maxWarnings = 0
-    it.showViolations = true
+// PMD — static analysis for Java sources
+extensions.configure(PmdExtension) {
+    it.ruleSetFiles = rootProject.files('etc/config/pmd/pmd.xml')
+    it.ruleSets = [] // clear defaults so only pmd.xml is used
     it.ignoreFailures = false
-    it.toolVersion = checkstyleVersion
+    it.consoleOutput = true
+    it.toolVersion = pmdVersion
 }
 
+// CodeNarc — static analysis for Groovy sources (unchanged)
 extensions.configure(CodeNarcExtension) {
     // Explicit `it` is required in extension configuration
     it.configFile = 
rootProject.layout.projectDirectory.file('etc/config/codenarc/codenarc.groovy').asFile
     it.toolVersion = codenarcVersion
 }
 
+// Spotless — formatting for Java sources, enforcing the same rules previously 
checked by Checkstyle:
+//   - 4-space indentation (palantirJavaFormat)
+//   - custom import ordering matching the former Checkstyle ImportOrderCheck 
groups
+//     (java|javax → groovy → jakarta → other → spring → grails → static last)
+//   - no unused imports, no trailing whitespace, newline at end of file
+spotless {
+    java {
+        palantirJavaFormat()
+        importOrder('java|javax', 
'groovy|org.apache.groovy|org.codehaus.groovy', 'jakarta', '', 
'io.spring|org.springframework', 'grails|org.apache.grails|org.grails', '\\#')
+        removeUnusedImports()
+        trimTrailingWhitespace()
+        endWithNewline()
+        target fileTree(project.projectDir) {
+            include 'src/main/**/*.java'
+        }
+    }
+}
+
 // Do not run Code Style checks if the property 'skipCodeStyle' is defined
-tasks.withType(Checkstyle).configureEach {
+tasks.withType(Pmd).configureEach {
     group = 'verification'
     onlyIf { !project.hasProperty('skipCodeStyle') }
 }
@@ -44,15 +64,19 @@ tasks.withType(CodeNarc).configureEach {
     group = 'verification'
     onlyIf { !project.hasProperty('skipCodeStyle') }
 }
+tasks.matching { it.name.startsWith('spotless') }.configureEach {
+    onlyIf { !project.hasProperty('skipCodeStyle') }
+}
 
 tasks.register('codeStyle') {
     group = 'verification'
     description = 'Runs code style checks'
-    dependsOn(tasks.withType(Checkstyle))
+    dependsOn(tasks.withType(Pmd))
     dependsOn(tasks.withType(CodeNarc))
+    dependsOn('spotlessCheck')
 }
 
-tasks.named('checkstyleTest') {
+tasks.named('pmdTest') {
     enabled = false // Do not check test sources at this time
 }
 
@@ -66,4 +90,9 @@ gradle.taskGraph.whenReady {
             enabled = false // Do not check test sources at this time
         }
     }
+    if (tasks.findByName('pmdIntegrationTest')) {
+        tasks.named('pmdIntegrationTest') {
+            enabled = false // Do not check test sources at this time
+        }
+    }
 }
diff --git a/grails-data-hibernate7/core/build.gradle 
b/grails-data-hibernate7/core/build.gradle
index 8b43bbe4af..c7c3d230c1 100644
--- a/grails-data-hibernate7/core/build.gradle
+++ b/grails-data-hibernate7/core/build.gradle
@@ -25,8 +25,6 @@ plugins {
     id 'java-library'
     id 'jacoco'
     id 'com.github.spotbugs'
-    id 'pmd'
-    id 'com.diffplug.spotless'
     id 'org.apache.grails.buildsrc.properties'
 }
 
@@ -138,6 +136,7 @@ dependencies {
 
 apply {
     from rootProject.layout.projectDirectory.file('gradle/java-config.gradle')
+    from 
rootProject.layout.projectDirectory.file('gradle/code-style-config.gradle')
     from 
rootProject.layout.projectDirectory.file('gradle/hibernate7-test-config.gradle')
     from 
rootProject.layout.projectDirectory.file('gradle/grails-data-tck-config.gradle')
     from rootProject.layout.projectDirectory.file('gradle/docs-config.gradle')
@@ -168,33 +167,6 @@ 
tasks.withType(com.github.spotbugs.snom.SpotBugsTask).configureEach {
     }
 }
 
-pmd {
-    consoleOutput = true
-    ignoreFailures = true
-//    ruleSets = ['category/java/bestpractices.xml', 
'category/java/errorprone.xml', 'category/java/security.xml']
-    // toolVersion = '7.0.0'   // optional: override default PMD version if 
needed
-}
-
 tasks.named('check') {
-    dependsOn 'spotbugsMain', 'pmdMain'
-}
-
-// 2. Configure Spotless
-spotless {
-    java {
-        // Use rootProject.projectDir to ensure the path is absolute from the 
root
-        def licenseFile = new File(rootProject.projectDir, 
'grails-forge/config/spotless.license.java')
-        if (licenseFile.exists()) {
-            licenseHeaderFile licenseFile
-        }
-
-        googleJavaFormat()
-
-        // This targets the specific file in your Checkstyle report
-        target 'src/main/java/**/*.java', 'src/main/groovy/**/*.java'
-
-        removeUnusedImports()
-        trimTrailingWhitespace()
-        endWithNewline()
-    }
+    dependsOn 'spotbugsMain'
 }

Reply via email to