Skip to content
Latchkey

Kotlin "w:" warnings failing the build with allWarningsAsErrors in CI

When allWarningsAsErrors = true, the Kotlin compiler turns every w: diagnostic into a build failure. A deprecation or unused-variable warning that is harmless locally will fail the CI job, often after a library or Kotlin version bump introduced a new warning.

What this error means

The Kotlin compile task fails and the log shows w: lines followed by "error: warnings found and -Werror specified", or the task simply fails with warnings that did not fail before.

Kotlin
> Task :app:compileKotlin FAILED
w: /app/src/main/kotlin/Repo.kt: (18, 9): 'getFoo(): String' is deprecated. Use bar() instead.
error: warnings found and -Werror specified

Common causes

allWarningsAsErrors promotes new warnings

A Kotlin or dependency upgrade emits a new deprecation or unchecked-cast warning; with -Werror on, that warning fails the build even though nothing you wrote changed.

A warning only appears under the CI Kotlin version

The runner resolved a different Kotlin plugin version whose warning set differs from a developer machine, so the same code warns only in CI.

How to fix it

Fix or suppress the specific warning

  1. Read the w: line to identify the exact deprecation or issue.
  2. Migrate to the recommended replacement, or annotate the narrow site with @Suppress("DEPRECATION").
  3. Rebuild so no w: remains.
Kotlin
@Suppress("DEPRECATION")
fun legacy() = api.getFoo()

Keep versions consistent so warning sets match

Pin the Kotlin Gradle plugin so CI and local builds emit the same warnings, then address them once.

build.gradle.kts
plugins {
    kotlin("jvm") version "2.0.21"
}

How to prevent it

  • Fix warnings promptly instead of letting them accumulate under -Werror.
  • Pin the Kotlin plugin version so the warning set is identical everywhere.
  • Scope @Suppress to the smallest site rather than disabling allWarningsAsErrors globally.

Related guides

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