Skip to content
Latchkey

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.

gradle output
> 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.

Terminal
./gradlew spotlessApply
git add -A   # commit the reformatted files

Verify the check passes locally

Re-run the check so CI will pass.

Terminal
./gradlew spotlessCheck

How to prevent it

  • Run spotlessApply in 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.

Frequently asked questions

What causes ""The following files had format violations""?
A file was edited without running the formatter, so it diverges from the configured style. spotlessCheck fails on any divergence.
How do I fix "The following files had format violations"?
Let Spotless rewrite the files to the canonical format, then commit.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card