Skip to content
Latchkey

Kotlin ktlint failures in CI

ktlint ran in check mode and found formatting or lint violations. This is a style gate that fails the build until the code conforms.

What this error means

The ktlintCheck task fails listing files, lines, and rule IDs that violate the ktlint ruleset. It is deterministic given the sources and config.

gradle
> Task :app:ktlintMainSourceSetCheck FAILED
src/main/kotlin/App.kt:12:1: Unexpected indentation (standard:indent)
src/main/kotlin/App.kt:20:80: Exceeded max line length (standard:max-line-length)

Common causes

Code committed without formatting

Changes were pushed without running ktlint, so indentation, imports, or line length diverge from the ruleset.

ktlint version or rule drift

A different ktlint version or editorconfig formats differently than what produced the committed code.

How to fix it

Auto-format with ktlint

Run the format task to fix most violations, then commit.

CI step
./gradlew ktlintFormat

Pin the ktlint version and editorconfig

  1. Pin the ktlint Gradle plugin version.
  2. Commit a shared .editorconfig so local and CI agree.
  3. Add a pre-commit hook to run ktlintFormat.

How to prevent it

  • Pin the ktlint plugin version.
  • Share an .editorconfig across the team.
  • Run ktlintFormat before pushing.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →