Configuration
Configuration options for library-api-watchdog.
Apply the Gradle plugin
Add the Space EAP repository to the plugin and dependency repositories:
pluginManagement {repositories {maven("https://packages.jetbrains.team/maven/p/kt-lib/eap")gradlePluginPortal()}}dependencyResolutionManagement {repositories {maven("https://packages.jetbrains.team/maven/p/kt-lib/eap")mavenCentral()}}
Then apply the plugin:
plugins {kotlin("library.api-watchdog") version "0.1.0-SNAPSHOT"}
library-api-watchdog is a Kotlin compiler plugin. It needs a Gradle project that applies the Kotlin plugin and turns on explicit API mode:
kotlin {explicitApi()}
The -Xexplicit-api compiler flag, and the warning variant of either form, also count. Without
explicit API mode enabled, library-api-watchdog registers no checks at all: there is no public API contract
to watch. The Gradle plugin prints a build warning when explicit API mode is not enabled.
What applying does
Applying the plugin:
- Registers the compiler plugin for every compilation in the project except test compilations: test sources are not published, so they carry no API contract to watch.
- Adds a dependency on
org.jetbrains.kotlin:kotlin-library-api-watchdog-plugin-annotations, a runtime library with the@Intentionally*exemption annotations. - Warns when explicit API mode is not enabled.
- Checks whether binary compatibility validation is enabled alongside it, printing a build warning with a setup snippet for either one that is missing. See below.
Errors by default
library-api-watchdog is intentionally restrictive by default: every check reports a compilation error until
configured otherwise. See The apiWatchdog extension
for demoting individual checks to warnings or disabling them, and
Exemptions and internal API for exempting a single declaration in place instead of
changing severity project-wide.
Adding the plugin to existing libraries
When added to an exiting library, chances are that the whole codebase will turn red, and most of the declarations reported can't be changes easily without breaking users.
Use updateBackwardsCompatibilityExempts task to mark existing APIs with @Intentionally*
annotations and ExemptionReason.FOR_BACKWARDS_COMPATIBILITY:
./gradlew updateBackwardsCompatibilityExempts
See Adding the plugin to existing libraries for more details.
Without Gradle
When invoking the compiler directly, configure severities with the repeatable plugin option:
-P plugin:org.jetbrains.kotlin.library.api.watchdog:diagnosticSeverity=<NAME>:<severity>
Parameters:
<NAME>is a diagnostic name. Any value from the Property reference is valid.<severity>iserror,warning, ornone.
The PUBLIC_TYPE_FROM_NON_TRANSITIVE_DEPENDENCY check is unavailable without Gradle because the
compiler alone cannot distinguish dependencies declared with api from those declared with
implementation.
For example, to demote undocumented public API to a warning use the following argument form:
-P plugin:org.jetbrains.kotlin.library.api.watchdog:diagnosticSeverity=UNDOCUMENTED_PUBLIC_API:warning
The apiWatchdog extension
Every property has a default value. For configurable checks it is WatchdogSeverity.ERROR,
for enabled/disabled switches is it true by default.
See the list of configurable properties:
apiWatchdog {suggestAbiValidation = truepublicTypesMustBeTransitiveDependencies = truepublicTypeWithInternalApi = trueopenApiWithoutSubclassOptIn = WatchdogSeverity.ERRORsubclassOptInWithoutMarkers = WatchdogSeverity.ERRORexhaustivePublicApi = WatchdogSeverity.ERRORundocumentedPublicApi = WatchdogSeverity.ERRORfunctionTypeAliasPublicApi = WatchdogSeverity.ERRORdataClassPublicApi = WatchdogSeverity.ERRORstatefulClassWithoutEquals = WatchdogSeverity.ERRORstatefulClassWithoutHashCode = WatchdogSeverity.ERRORstatefulClassWithoutToString = WatchdogSeverity.ERRORmutableCollectionPublicApi = WatchdogSeverity.ERRORpairOrTriplePublicApi = WatchdogSeverity.ERRORbooleanParameterPublicApi = WatchdogSeverity.ERRORnullableBooleanPublicApi = WatchdogSeverity.ERRORrequiredParameterAfterOptional = WatchdogSeverity.ERRORinconsistentParameterOrderInOverloads = WatchdogSeverity.ERRORinlineFunctionWithLogic = WatchdogSeverity.ERRORdslMarkerNoopTarget = WatchdogSeverity.ERRORdslMarkerWithoutExplicitTargets = WatchdogSeverity.ERRORdslMarkerNoopTypePosition = WatchdogSeverity.ERRORjavaInterop {// One switch for the whole Java interop group,// it overrides the severities below.enabled = truemangledJvmNamePublicApi = WatchdogSeverity.ERRORkotlinOnlyApiWithoutJvmSynthetic = WatchdogSeverity.ERRORcompanionApiWithoutJvmStatic = WatchdogSeverity.ERRORcompanionConstantWithoutJvmField = WatchdogSeverity.ERRORtopLevelApiWithoutJvmName = WatchdogSeverity.ERRORdefaultParametersWithoutJvmOverloads = WatchdogSeverity.ERROR}}
Severity semantics
Each check's severity is a WatchdogSeverity:
| Value | Effect |
|---|---|
ERROR | Fails the compilation. This is the default for every configurable diagnostic. |
WARNING | Reported as a compiler warning, the build still succeeds. |
NONE | The check is disabled entirely. |
EXEMPTION_WITHOUT_EXPLANATION has no matching property and is always an error.
PUBLIC_TYPE_WITH_INTERNAL_API and
PUBLIC_TYPE_FROM_NON_TRANSITIVE_DEPENDENCY are always errors when
enabled. Their Gradle properties are Boolean whole-check switches rather than severities. See
Exemptions and internal API.
Property reference
The last six properties live inside the javaInterop { } block. They only run in JVM
compilations, and javaInterop.enabled (default true) is a single switch for all of them: set
it to false and every one of the six resolves to NONE, no matter what its own property says.
See Java interop checks for more details.
Binary compatibility validation suggestion
suggestAbiValidation (default is true) controls a build warning unrelated to any
diagnostic. If neither the Kotlin Gradle plugin's built-in ABI validation nor the standalone
Binary Compatibility Validator plugin is enabled alongside the watchdog, the plugin warns that
incompatible changes to already-shipped API would go unnoticed. Set it to false to silence the
warning:
apiWatchdog {suggestAbiValidation = false}
See Binary compatibility validation suggestion for more details.