Welcome | detekt (original) (raw)

detekt in action

Features

Quick Start with Gradle

Apply the following configuration to your Gradle project build file:

plugins {
    id("io.gitlab.arturbosch.detekt") version("1.23.8")
}

repositories {
    mavenCentral()
}

You can find what is the latest version of detekt in the release notes.

Once you have set up detekt in your project, simply run gradlew detekt.

To change the default behaviour of detekt rules, first generate yourself a detekt configuration file by runninggradlew detektGenerateConfig task and applying any changes to the generated file.

Don't forget to reference the newly generated config inside the detekt { } closure. Optionally, it is possible to slim down the configuration file to only the changes from the default configuration, by applying thebuildUponDefaultConfig option:

detekt {
    toolVersion = "1.23.8"
    config.setFrom(file("config/detekt/detekt.yml"))
    buildUponDefaultConfig = true
}

To enable/disable detekt reports use the withType method to set defaults for all detekt tasks at once:

// Kotlin DSL
tasks.withType<Detekt>().configureEach {
    reports {
        xml.required.set(true)
        html.required.set(true)
        sarif.required.set(true)
        md.required.set(true)
    }
}
// Groovy DSL
tasks.withType(Detekt).configureEach {
    reports {
        xml.required.set(true)
        html.required.set(true)
        sarif.required.set(true)
        md.required.set(true)
    }
}

See reporting docs for more details on configuring reports.

Adding more rule sets

detekt itself provides a wrapper over ktlint as the formatting rule set which can be easily added to the Gradle configuration:

dependencies {
    detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.23.8")
}