Install
brew install costajohnt/tap/groovyfmt
Or npm install --save-dev groovyfmt, cargo install --locked groovyfmt, the ghcr.io/costajohnt/groovyfmt Docker image, or a prebuilt binary for Linux, macOS or Windows from the releases. Then run groovyfmt --check in a repository.
What it does
-
Safe formatting
By default it re-indents from the parse tree, trims trailing whitespace and collapses blank lines. Every result is re-parsed and token-compared with the input, and a file is left alone if anything other than whitespace would change.
-
Linting that knows Gradle and Jenkins
84 rules, with CodeNarc names for the general ones. The Gradle and Jenkinsfile rules catch what usually breaks only when the build runs, like APIs removed in Gradle 9 and classes Groovy 4 moved.
--fixrepairs the safe cases.$ groovyfmt --lint build.gradle:3:1: GradleRemovedApi: The project property `sourceCompatibility` was removed in Gradle 9.0 with the plugin conventions; use java { sourceCompatibility = ... } -
Fast
Checks the 635-file Spock repository in 0.2 seconds on a laptop. It fits in a pre-commit hook or an editor's format-on-save.
-
Tested on real code
Run against more than 5,500 open source repositories. It found real bugs in them, and 16 fixes have been merged upstream so far.
-
CI and editors
A GitHub Action, pre-commit hooks, SARIF and GitHub annotations for CI. A built-in language server, with extensions for VS Code and JetBrains IDEs and setup for Neovim, Helix and Zed.
- uses: costajohnt/groovyfmt@v0.30.2
Who it's for
Teams with Gradle builds, Jenkins pipelines or Groovy code who want consistent formatting and early warnings in CI, without starting a JVM. Coming from CodeNarc or npm-groovy-lint? groovyfmt --import-codenarc converts your config.