Document CodeNarc configuration for Grails projects#15404
Document CodeNarc configuration for Grails projects#15404jamesfredley merged 4 commits intoapache:7.0.xfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds documentation to the Grails user guide describing how to configure and use CodeNarc in Grails projects, including the known GORM AST-related incompatibilities with importing built-in CodeNarc rulesets.
Changes:
- Added a new “Code Quality with CodeNarc” entry to the Testing chapter TOC.
- Added a new
codeQuality.adocguide covering Gradle setup, the ruleset-import pitfall, and recommended per-rule configuration. - Documented using a separate, more lenient CodeNarc configuration for test sources.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| grails-doc/src/en/guide/toc.yml | Adds codeQuality page under the Testing chapter navigation. |
| grails-doc/src/en/guide/testing/codeQuality.adoc | New documentation page describing CodeNarc setup and Grails/GORM-specific caveats. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
jdaugherty
left a comment
There was a problem hiding this comment.
I don't dispute this is good to add, but I'm currently reworking the "example" project for this and this overlaps strongly with that work.
The examples you show do not follow the feedback that @matrei has given on the sample project. Can we update these?
…eedback Match the documented ruleset exactly to grails-core's own codenarc.groovy (adding MissingBlankLineBeforeAnnotatedField and UnnecessaryGString, removing 12 extra rules not in the canonical config). Fix CodeNarc version to 3.6.0 matching gradle.properties. Replace ignoreFailures with strict maxPriority violation thresholds matching grails-server-timing's feedback branch pattern. Assisted-by: Claude Code <Claude@Claude.ai>
|
Updated to match the examples exactly. |
- Create 'Building a Successful Application' top-level section - Rename to 'Code Analysis and Styling for Groovy' (CodeNarc is an implementation detail, not a section header) - Update Gradle config to use extensions.configure(CodeNarcExtension) matching grails-server-timing best practices - Update test ruleset config to use tasks.named() API - Add grails-server-timing as reference for complete working example Assisted-by: Claude Code <Claude@Claude.ai>
Summary
Adds a new "Code Quality with CodeNarc" section to the Testing chapter of the Grails documentation, covering Gradle plugin setup, the GORM AST transformer compatibility issue with ruleset imports, and the recommended individual-rule configuration approach.
Problem
When Grails developers integrate CodeNarc for static analysis, the natural approach is to import pre-built rulesets:
ruleset { ruleset('rulesets/basic.xml') ruleset('rulesets/formatting.xml') }This fails in Grails projects because some CodeNarc rules ("enhanced" rules) perform semantic analysis at Groovy compiler phase 4. These rules attempt to resolve GORM AST-transformed classes (
OrderedGormTransformation,ServiceTransformation) that are not available on CodeNarc's classpath. The result isClassNotFoundExceptionorNoClassDefFoundErrorduring analysis.Adding
compilationClasspathto the CodeNarc Gradle task helps with basic class resolution but does not make GORM's transformation processors available, so enhanced rules still fail.There is currently no mention of CodeNarc anywhere in the Grails documentation.
Solution
The new
codeQuality.adocsection documents:-groovy-4.0artifact variant and strict violation thresholdsruleset()imports fail in Grails projectsThe documented ruleset matches grails-core's canonical
codenarc.groovyexactly, and the Gradle configuration follows the pattern established ingrails-server-timing's feedback branch (strictmaxPriorityNViolations = 0thresholds, noignoreFailures).Files Changed
grails-doc/src/en/guide/toc.yml- AddedcodeQualityentry undertesting:sectiongrails-doc/src/en/guide/testing/codeQuality.adoc- New documentation fileVerification
build-logic/plugins/src/main/resources/META-INF/org.apache.grails.buildsrc.codestyle/codenarc/codenarc.groovy3.6.0-groovy-4.0) matchesgradle.propertiesignoreFailures) matchesgrails-server-timingfeedback branch