Skip to content
Latchkey

detekt "Build failed with N weighted issues" in CI

detekt is a static analyzer for Kotlin. By default maxIssues is low, so any new violation makes the detekt task fail. In CI this catches complexity, style, and potential-bug findings; the log lists each rule and location.

What this error means

The detekt (or detektMain) task fails with "Analysis failed with N weighted issues" or "Build failed with N weighted issues" and a list of rule violations.

detekt
> Task :app:detekt FAILED
Complexity - LongMethod: The function process is too long (72). ... Repo.kt:40:5
Analysis failed with 3 weighted issues.

Common causes

New violations exceeded the issue threshold

A code change introduced findings above maxIssues, so detekt fails the build to keep quality gated.

A ruleset or detekt version bump added rules

Upgrading detekt or its config enabled rules that now flag existing code that previously passed.

How to fix it

Fix or explicitly suppress the flagged code

  1. Read each rule and file:line in the report.
  2. Refactor to satisfy the rule, or add a scoped @Suppress("RuleName") with justification.
  3. Re-run ./gradlew detekt to confirm zero weighted issues.
Terminal
./gradlew detekt

Baseline pre-existing issues on adoption

When first adding detekt to a large codebase, generate a baseline so only new issues fail CI.

Terminal
./gradlew detektBaseline

How to prevent it

  • Run detekt locally (or as a pre-push hook) before CI.
  • Use a baseline when adopting detekt so only new issues gate the build.
  • Bump detekt deliberately and address newly enabled rules in one change.

Related guides

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