Edit me

detekt in action

Features

  • Code smell analysis for your Kotlin projects
  • Complexity report based on logical lines of code, McCabe complexity and amount of code smells
  • Highly configurable (rule set or rule level)
  • Suppress findings with Kotlin’s @Suppress and Java’s @SuppressWarnings annotations
  • Specify code smell thresholds to break your build or print a warning
  • Code Smell baseline and ignore lists for legacy projects
  • Gradle plugin for code analysis via Gradle builds
  • Gradle tasks to use local IntelliJ distribution for formatting and inspecting Kotlin code
  • Optionally configure detekt for each sub module by using profiles (gradle-plugin)
  • SonarQube integration
  • Extensible by own rule sets and FileProcessListener's
  • IntelliJ integration
  • Unofficial Maven plugin by Ozsie

Quick Start with Gradle

Apply following configuration to your gradle build file and run gradle detekt:

buildscript {
    repositories {
        jcenter()
    }
}

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

detekt {
    toolVersion = "[version]"
    input = files("src/main/kotlin")
    filters = ".*/resources/.*,.*/build/.*"
    config = files("path/to/config.yml")
}

If you want to change the default behaviour of detekt rules, first generate yourself a detekt configuration file and apply your changes:

gradle detektGenerateConfig

Then reference the config inside the defaultProfile-closure:

config = files("default-detekt-config.yml")

To enable/disable detekt reports and to configure their output directories edit the detekt { } closure:

detekt {
    reports {
        xml {
            enabled = true
            destination = file("path/to/destination.xml")
        }
        html {
            enabled = true
            destination = file("path/to/destination.html")
        }
    }
}

Adding more rule sets

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

dependencies {
    detektPlugins "io.gitlab.arturbosch.detekt:detekt-formatting:[version]"
}

Likewise custom extensions can be added to detekt.

Tags: