ktlint "not formatted" / lint errors failing CI
ktlint enforces a Kotlin code style. The ktlintCheck task fails when a file is "not formatted" or violates a rule. It reports each file, line, and rule id, and refuses to pass CI until the code matches the configured style.
What this error means
The ktlintCheck (or ktlintMainSourceSetCheck) task fails with lines like "Main.kt:12:1: Unexpected indentation (standard:indent)" or a summary that files are not formatted.
> Task :app:ktlintMainSourceSetCheck FAILED
/app/src/main/kotlin/Main.kt:12:1: Unexpected indentation (4) (should be 8) (standard:indent)
/app/src/main/kotlin/Main.kt:20:80: Exceeded max line length (standard:max-line-length)Common causes
Code was not run through the formatter
Files were committed without applying ktlint formatting, so the check finds style violations.
A ktlint or editorconfig rule changed
Upgrading ktlint or changing .editorconfig altered the expected style, so previously passing code now fails.
How to fix it
Auto-format then commit
- Run the ktlint format task to fix violations automatically.
- Review and commit the formatting changes.
- Re-run
ktlintCheckto confirm a clean pass.
./gradlew ktlintFormat
./gradlew ktlintCheckPin the ktlint version and editorconfig
Keep the ktlint version and .editorconfig consistent so local formatting matches CI exactly.
# .editorconfig
[*.{kt,kts}]
max_line_length = 120How to prevent it
- Run
ktlintFormatin a pre-commit or pre-push hook. - Pin the ktlint plugin version so CI and local styles match.
- Keep
.editorconfigcommitted and consistent across the team.