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
- Read each rule and file:line in the report.
- Refactor to satisfy the rule, or add a scoped
@Suppress("RuleName")with justification. - Re-run
./gradlew detektto confirm zero weighted issues.
Terminal
./gradlew detektBaseline pre-existing issues on adoption
When first adding detekt to a large codebase, generate a baseline so only new issues fail CI.
Terminal
./gradlew detektBaselineHow 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
ktlint "not formatted" / lint errors failing CIFix ktlint failures in CI - the ktlintCheck task reports files that are "not formatted" or lint errors, faili…
Kotlin "w:" warnings failing the build with allWarningsAsErrors in CIFix Kotlin builds where "w: ... " warnings fail CI because allWarningsAsErrors is on - the compiler promotes…
kotlin.test / MockK test failures and verification errors in CIFix Kotlin test failures in CI using kotlin.test assertions and MockK - assertion failures, MockK "no answer…