detekt


Meet detekt, a static code analysis tool for the Kotlin programming language.
Visit the project website for installation guides, rule descriptions, configuration options and more.

Features
- Code smell analysis for your Kotlin projects.
- Highly configurable rule sets.
- Generate baselines to suppress existing issues for legacy projects while making sure no new issues are introduced.
- Suppress issues in source files using
@Suppress
annotations.
- Support for different report formats: HTML, Markdown, SARIF, XML (Checkstyle) and custom reports.
- Extend detekt with custom rule sets and reports.
- Complexity reports based on lines of code, cyclomatic complexity and number of code smells.
- First party integration with Gradle with our Gradle plugin.
- A community of third party plugins that adds more rules and features to detekt.
Quick-Links
Quick Start ...
with the command-line interface
curl -sSLO https://github.com/detekt/detekt/releases/download/v[version]/detekt-cli-[version]-all.jar
java -jar detekt-cli-[version]-all.jar --help
You can find other ways to install detekt here
with Gradle
plugins {
id("io.gitlab.arturbosch.detekt").version("[version]")
}
repositories {
mavenCentral()
}
detekt {
buildUponDefaultConfig = true
allRules = false
config.setFrom("$projectDir/config/detekt.yml")
baseline = file("$projectDir/config/baseline.xml")
}
tasks.withType<Detekt>().configureEach {
reports {
html.required.set(true)
xml.required.set(true)
txt.required.set(true)
sarif.required.set(true)
md.required.set(true)
}
}
tasks.withType(Detekt).configureEach {
jvmTarget = "1.8"
}
tasks.withType(DetektCreateBaselineTask).configureEach {
jvmTarget = "1.8"
}
tasks.withType<Detekt>().configureEach {
jvmTarget = "1.8"
}
tasks.withType<DetektCreateBaselineTask>().configureEach {
jvmTarget = "1.8"
}
See maven central for releases and sonatype for snapshots.
If you want to use a SNAPSHOT version, you can find more info on this documentation page.
Requirements
Gradle 6.7.1+ is the minimum requirement. However, the recommended versions together with the other tools recommended versions are:
1.22.0 | 7.5.1 | 1.7.21 | 7.3.1 | 1.8 | 17 |
The list of recommended versions for previous detekt version is listed here.
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:[version]")
}
Similarly, there are extra rule sets available for detekt from detekt:
dependencies {
detektPlugins("io.gitlab.arturbosch.detekt:detekt-rules-libraries:[version]")
detektPlugins("io.gitlab.arturbosch.detekt:detekt-rules-ruleauthors:[version]")
}
For more info visit the Detekt Marketplace.
Likewise custom extensions can be added to detekt.
Contributing
See CONTRIBUTING
Thanks to all the people who contributed to detekt!

Mentions

As mentioned in...
Integrations:
Custom rules and reports from 3rd parties can be found on our Detekt Marketplace.
Credits