Skip to content

j-roskopf/KotlinWarningBaselineGenerator

Repository files navigation

Kotlin Warning Baseline Generator

Maveb Central License Release Workflow Kotlin Weekly


A gradle plugin for detecting when new Kotlin warnings are added.

This is spiritually similar to android.kotlinOptions.allWarningsAsError or -Werror in your Kotlin / Android project. If you can or already do use those, this plugin isn't of much value to you. The value of this plugin is to people who can't enable those settings due to legacy modules having too many errors to fix at once. The Gradle tasks added will allow you to generate, check, and delete kotlin warning baselines.

  • Generate

Generating the baseline for your project can be done via ./gradlew <VARIANT>WriteKotlinWarningBaseline (example: ./gradlew releaseWriteKotlinWarningBaseline) You can also generate the baseline for a specific module via ./gradlew :<MODULE>:<VARIANT>WriteKotlinWarningBaseline (example: ./gradlew :app:releaseWriteKotlinWarningBaseline)

  • Check

Checking the current code against the baseline can be done via ./gradlew <VARIANT>CheckKotlinWarningBaseline (example: ./gradlew releaseCheckKotlinWarningBaseline) You can also check the baseline for a specific module via ./gradlew :<MODULE>:<VARIANT>CheckKotlinWarningBaseline (example: ./gradlew :app:releaseCheckKotlinWarningBaseline))

  • Remove

Baselines can be deleted via ./gradlew removeKotlinWarningBaseline Baselines for a specific module can be done via ./gradlew :<MODULE>:removeKotlinWarningBaseline

Adding To Your Project

In your root build file:

plugins {
    id("com.joetr.kotlin.warning.baseline.generator") version "<latest version>" apply false
}

In any module you want to apply checks:

plugins {
    id("com.joetr.kotlin.warning.baseline.generator")
}

Configuration

Right now, warnings can be observed from main, unit test, or android test source sets and is configurable via the following DSL in your build.gradle.kts:

kotlinWarningBaselineGenerator {
    // default is set to just KotlinCompileTask.MAIN
    kotlinCompileTasksToConfigure.set(
        listOf(
            KotlinCompileTask.MAIN,
            KotlinCompileTask.UNIT_TEST,
            KotlinCompileTask.ANDROID_TEST,
        )
    )
}

Note - Since this plugin requires all kotlin warnings to be output during task execution, incremental compilation + up to date checks for the kotlin compile task are modified when executing the check / generate gradle tasks.

Multiplatform

In a Multiplatform project, Kotlin Warning Baseline Generator adds the same 2 Check and Generate tasks (as well as a root removeKotlinWarningBaseline task) for each supported target.

JVM

./gradlew :desktopApp:jvmWriteKotlinWarningBaseline ./gradlew :desktopApp:jvmCheckKotlinWarningBaseline

Android

./gradlew :androidApp:androidReleaseCheckKotlinWarningBaseline ./gradlew :androidApp:androidReleaseWriteKotlinWarningBaseline

Web

./gradlew :webApp:jsWriteKotlinWarningBaseline ./gradlew :webApp:jsCheckKotlinWarningBaseline

iOS

WIP

Signing locally

This is required to test.

In memory GPG key - https://vanniktech.github.io/gradle-maven-publish-plugin/central/#in-memory-gpg-key

signing.keyId=LAST_8_DIGITS_OF_KEY
signing.password=PASSWORD_USED_TO_GENERATE_KEY
signing.secretKeyRingFile=/Users/YOURUSERNAME/.gnupg/kotlinwarningbaselinegenerator.gpg (or wherever you stored the keyring you generated earlier)

Prior Art

https://github.com/Doist/kotlin-warning-baseline - Relation

About

A Gradle plugin to generate baselines for Kotlin warnings

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages