Skip to content

Document CodeNarc configuration for Grails projects#15404

Merged
jamesfredley merged 4 commits intoapache:7.0.xfrom
jamesfredley:docs/codenarc-gorm-compatibility
Feb 19, 2026
Merged

Document CodeNarc configuration for Grails projects#15404
jamesfredley merged 4 commits intoapache:7.0.xfrom
jamesfredley:docs/codenarc-gorm-compatibility

Conversation

@jamesfredley
Copy link
Contributor

@jamesfredley jamesfredley commented Feb 17, 2026

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 is ClassNotFoundException or NoClassDefFoundError during analysis.

Adding compilationClasspath to 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.adoc section documents:

  1. Gradle plugin setup - applying the CodeNarc plugin with the correct -groovy-4.0 artifact variant and strict violation thresholds
  2. GORM AST compatibility - explains why ruleset() imports fail in Grails projects
  3. Recommended configuration - the exact ruleset from grails-core's own build, listing individual rules explicitly to avoid enhanced rules that require GORM's AST infrastructure
  4. Separate test ruleset - guidance on configuring a more lenient ruleset for Spock specs
  5. Reference - links to grails-core's own CodeNarc config as the canonical starting point

The documented ruleset matches grails-core's canonical codenarc.groovy exactly, and the Gradle configuration follows the pattern established in grails-server-timing's feedback branch (strict maxPriorityNViolations = 0 thresholds, no ignoreFailures).

Files Changed

  • grails-doc/src/en/guide/toc.yml - Added codeQuality entry under testing: section
  • grails-doc/src/en/guide/testing/codeQuality.adoc - New documentation file

Verification

  • The documented ruleset is identical to build-logic/plugins/src/main/resources/META-INF/org.apache.grails.buildsrc.codestyle/codenarc/codenarc.groovy
  • The CodeNarc version (3.6.0-groovy-4.0) matches gradle.properties
  • The Gradle configuration pattern (strict violation thresholds, no ignoreFailures) matches grails-server-timing feedback branch

Copilot AI review requested due to automatic review settings February 17, 2026 16:07
@jamesfredley jamesfredley self-assigned this Feb 17, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.adoc guide 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.

Copy link
Contributor

@jdaugherty jdaugherty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@jamesfredley jamesfredley marked this pull request as draft February 17, 2026 19:58
…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>
@jamesfredley
Copy link
Contributor Author

Updated to match the examples exactly.

@jamesfredley jamesfredley marked this pull request as ready for review February 19, 2026 00:34
@jamesfredley jamesfredley requested a review from matrei February 19, 2026 00:34
@jamesfredley jamesfredley moved this to In Progress in Apache Grails Feb 19, 2026
@jamesfredley jamesfredley added this to the grails:7.0.8 milestone Feb 19, 2026
- 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>
@jamesfredley jamesfredley dismissed jdaugherty’s stale review February 19, 2026 16:02

Commit with changes pushed

@jamesfredley jamesfredley merged commit dd033e5 into apache:7.0.x Feb 19, 2026
32 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Apache Grails Feb 19, 2026
@jamesfredley jamesfredley deleted the docs/codenarc-gorm-compatibility branch February 19, 2026 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants

Comments