mirror of
https://github.com/jlengrand/detekt.git
synced 2026-03-10 08:11:23 +00:00
Document how to create a common baseline file for multi module gradle projects - Closes #2100 (#2140)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import com.jfrog.bintray.gradle.BintrayExtension
|
||||
import groovy.lang.GroovyObject
|
||||
import io.gitlab.arturbosch.detekt.Detekt
|
||||
import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask
|
||||
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
|
||||
import org.gradle.api.tasks.testing.logging.TestLogEvent
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
@@ -347,3 +348,17 @@ val detektAll by tasks.registering(Detekt::class) {
|
||||
txt.enabled = false
|
||||
}
|
||||
}
|
||||
|
||||
val detektProjectBaseline by tasks.registering(DetektCreateBaselineTask::class) {
|
||||
description = "Overrides current baseline."
|
||||
buildUponDefaultConfig.set(true)
|
||||
ignoreFailures.set(true)
|
||||
parallel.set(true)
|
||||
setSource(files(rootDir))
|
||||
config.setFrom(files("$rootDir/config/detekt/detekt.yml"))
|
||||
baseline.set(file("$rootDir/config/detekt/baseline.xml"))
|
||||
include("**/*.kt")
|
||||
include("**/*.kts")
|
||||
exclude("**/resources/**")
|
||||
exclude("**/build/**")
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class MainSpec : Spek({
|
||||
emptyArray()
|
||||
).forEach { args ->
|
||||
|
||||
val expectedRunnerClass = when {
|
||||
val expectedRunnerClass = when {
|
||||
args.contains("--generate-config") -> ConfigExporter::class
|
||||
args.contains("--run-rule") -> SingleRuleRunner::class
|
||||
args.contains("--print-ast") -> AstPrinter::class
|
||||
@@ -41,5 +41,4 @@ class MainSpec : Spek({
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
@@ -66,7 +66,7 @@ private class DefaultCliInvoker(private val project: Project) : DetektInvoker {
|
||||
throw GradleException("MaxIssues or failThreshold count was reached.")
|
||||
}
|
||||
INVALID_CONFIG -> throw GradleException("Invalid detekt configuration file detected.")
|
||||
else -> throw GradleException("Unexpected detekt exit with code '${exitValue}'.")
|
||||
else -> throw GradleException("Unexpected detekt exit with code '$exitValue'.")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,68 @@ the `--report txt:path/to/report` cli flag.
|
||||
</SmellBaseline>
|
||||
```
|
||||
|
||||
#### Gradle
|
||||
|
||||
If you are using the gradle-plugin run the `detektBaseline` task to generate yourself a `baseline.xml`.
|
||||
This will create one baseline file per Gradle module.
|
||||
As this might not be the desired behavior for a multi module project, think about implementing
|
||||
a custom meta baseline task:
|
||||
|
||||
Gradle-DSL
|
||||
|
||||
```gradle
|
||||
subprojects {
|
||||
detekt {
|
||||
// ...
|
||||
baseline = file("${rootProject.projectDir}/config/baseline.xml")
|
||||
// ...
|
||||
}
|
||||
}
|
||||
|
||||
task detektProjectBaseline(type: io.gitlab.arturbosch.detekt.DetektCreateBaselineTask) {
|
||||
description = "Overrides current baseline."
|
||||
ignoreFailures.set(true)
|
||||
parallel.set(true)
|
||||
buildUponDefaultConfig.set(true)
|
||||
setSource(files(rootDir))
|
||||
config.setFrom(files("$rootDir/config/detekt/detekt.yml"))
|
||||
baseline.set(file("$rootDir/config/detekt/baseline.xml"))
|
||||
include("**/*.kt")
|
||||
include("**/*.kts")
|
||||
exclude("**/resources/**")
|
||||
exclude("**/build/**")
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Kotlin-DSL
|
||||
|
||||
```kotlin
|
||||
subprojects {
|
||||
detekt {
|
||||
// ...
|
||||
baseline = file("${rootProject.projectDir}/config/baseline.xml")
|
||||
// ...
|
||||
}
|
||||
}
|
||||
|
||||
val detektProjectBaseline by tasks.registering(DetektCreateBaselineTask::class) {
|
||||
description = "Overrides current baseline."
|
||||
buildUponDefaultConfig.set(true)
|
||||
ignoreFailures.set(true)
|
||||
parallel.set(true)
|
||||
setSource(files(rootDir))
|
||||
config.setFrom(files("$rootDir/config/detekt/detekt.yml"))
|
||||
baseline.set(file("$rootDir/config/detekt/baseline.xml"))
|
||||
include("**/*.kt")
|
||||
include("**/*.kts")
|
||||
exclude("**/resources/**")
|
||||
exclude("**/build/**")
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
#### FAQ
|
||||
|
||||
Be aware that auto formatting cannot be combined with the `baseline`.
|
||||
The signatures for a `;` for example would be too ambiguous.
|
||||
|
||||
Reference in New Issue
Block a user