You can add static code analysis to kotlin using detekt. Below is the basic configuration, for more details about configuration and rules go to project page: https://arturbosch.github.io/detekt/.
//add to top-level gradle file
buildscript {
ext {
detektVersion = '1.0.0.RC7'
}
repositories {
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:$detektVersion"
}
//add to module gradle file
apply plugin: 'io.gitlab.arturbosch.detekt'
detekt {
version = detektVersion
profile("main") {
output = "$project.projectDir/build/reports/detekt"
config = "$projectDir/scripts/detekt-config.yml"
parallel = true
}
}Gradle step for checking is detektCheck. If you want to enable it on an already existing projects, there will probably be some problems which you might not want to fix immediately - in that case, you can create a baseline file first, based on which only new problems will be reported.
First add the baseline file setup to your detekt setup in the module gradle file:
detekt {
profile("main") {
baseline = file("../scripts/detekt-baseline.xml")
}
}
Then create the baseline file to be used with detektBaseline gradle step. Further detektCheck calls won't fail the build and will report only new problems.