Skip to main content

Get started

library-api-watchdog helps library authors to detect public API declarations that are hard to evolve. It runs as a set of Kotlin K2 compiler frontend checks in the module it is applied to.

The tool is intentionally restrictive by default: all checks are enabled and report a compilation error until demoted to a warning, disabled, or exempted in place.

What it looks like

A public data class that hands out a mutable collection, without documentation, triggers three diagnostics at once:

tip

Diagnostics in code examples are interactive. Hover over or focus an underlined range to read the diagnostic and follow its link to the full documentation.

public data class Config(
public val tags: MutableList<String>
)
  • The generated copy and componentN functions and the constructor bake the exact property list into the compiled API.
  • tags shares a mutable collection across the API boundary: it is unclear whether user-side and library-side mutations affect each other.
  • Neither the class nor the property has KDoc.

The fixed version documents the declaration, exposes a read-only collection, and drops the data class shape, while having its equals, hashCode, and toString generated by Poko:

/**
* Immutable request configuration.
*
* @property tags Labels attached to this configuration.
*/
@Poko
public class Config(public val tags: List<String>)

Quick setup

Add Kotlin and Watchdog plugins and enable explicit API mode:

build.gradle.kts
plugins {
kotlin("multiplatform") version "2.4.0"
kotlin("library.api-watchdog") version "0.1.0-SNAPSHOT"
}
kotlin {
explicitApi() // Required to enable checks
}

The plugin also works for Kotlin/JVM only projects.

See Configuration for full configuration options and build suggestions overview.

All checks

API surface checks

Checks about how callers use the source API ignore declarations that are visible only through @PublishedApi: those declarations remain internal and cannot be named by library users. Checks that protect binary linkage still include them where noted.

Java interop checks

These checks only run in JVM compilations, and only pay off for libraries that support Java consumers. The whole group is disabled with javaInterop { enabled = false }. See Java interop checks for the group overview.

DSL marker checks

Meaningful exemptions

  • Exemptions without explanation: an @Intentionally* exemption annotation left with the default OTHER reason and a blank description explains nothing. This diagnostic is always an error and can't be configured like the others.

Next steps