AG
11/25/2021, 1:59 PMtask detektProjectBaseline(type: DetektCreateBaselineTask, group: "detekt") {
description = "Overrides current baseline."
buildUponDefaultConfig = false
ignoreFailures.set(true)
parallel.set(true)
setSource(files(rootDir))
config.setFrom(files("$rootDir/quality/detekt/detekt-config.yml"))
baseline.set(file("$rootDir/quality/detekt/baseline.xml"))
include("**/*.kt")
exclude("**/res/**", "**/build/**", "**/*.kts", "**/test/**", "**/androidTest/**")
classpath.setFrom(project.configurations.getByName("detekt"))
}
and I have another task which runs on files that I'm passing through -PinputFiles gradle param
task detektChangedFiles(type: Detekt, group: "detekt") {
description = "Runs over changed files."
buildUponDefaultConfig = false
ignoreFailures = false
parallel = true
if (project.hasProperty("inputFiles")) {
setSource(files(inputFiles.split('\n')))
}
config.setFrom(file("$rootDir/quality/detekt/detekt-config.yml"))
baseline.set(file("$rootDir/quality/detekt/baseline.xml"))
include("**/*.kt")
exclude("**/res/**", "**/build/**", "**/*.kts", "**/test/**", "**/androidTest/**")
classpath.setFrom(project.configurations.getByName("detekt"))
reports {
xml {
enabled = true
destination = file("build/reports/detekt.xml")
}
html {
enabled = true
destination = file("build/reports/detekt.html")
}
}
}
The problem is that after running detektChangedFiles I'm getting issues like UnnecessaryLet that my baseline doesn't contain for that file. Seems baseline generation task ignores some rulesgammax
11/25/2021, 2:13 PMclasspath.setFrom(project.configurations.getByName(“detekt”))From both tasks. What is happening is that, for some reasons, the
detektChangedFiles is running with type resolution while the former task is not.gammax
11/25/2021, 2:13 PMUnnecessaryLet is a rule that requires type resolution, and would not work with your approach.AG
11/25/2021, 2:28 PMclasspath.setFrom(project.configurations.getByName("detekt"))gammax
11/25/2021, 2:36 PMclasspath.setFrom(project.configurations.getByName("detekt")) will set the classpath to just the files in the detekt configuration, which is not enough to resolve all the types for your Android project (you’re missing out all the 3rd party dependencies).
You should either:
• Use the tasks that the Detekt Gradle Plugin is creating from you
• Switch to don’t use type resolution at all (i.e. don’t pass an incomplete classpath ).AG
11/25/2021, 2:57 PMgammax
11/25/2021, 2:57 PMAG
11/25/2021, 5:56 PMgammax
11/25/2021, 5:57 PM