Gradle Spotless "format violations were found" - Fix in CI
The Spotless spotlessCheck task found files that do not match the configured formatter (google-java-format, ktlint, Prettier, etc.) and failed the build. Spotless is a formatting gate - spotlessApply rewrites the files to satisfy it.
What this error means
The build fails with The following files had format violations and a list of files, plus Run 'gradlew spotlessApply' to fix these violations. Compilation and tests are unaffected - only formatting failed.
> Task :app:spotlessJavaCheck FAILED
The following files had format violations:
src/main/java/com/example/App.java
@@ -10,3 +10,3 @@
Run 'gradlew spotlessApply' to fix these violations.Common causes
Code not formatted to the Spotless config
A file was edited without running the formatter, so it diverges from the configured style. spotlessCheck fails on any divergence.
Formatter version or rules changed
Bumping the formatter version or tightening the Spotless config reformats expectations, so previously-passing files now show violations.
How to fix it
Run spotlessApply and commit the result
Let Spotless rewrite the files to the canonical format, then commit.
./gradlew spotlessApply
git add -A # commit the reformatted filesVerify the check passes locally
Re-run the check so CI will pass.
./gradlew spotlessCheckHow to prevent it
- Run
spotlessApplyin a pre-commit hook so violations never reach CI. - Pin the formatter version so the canonical format is stable.
- Keep the Spotless config in sync with the team’s editor/format settings.