Hello :wave: I want to setup detekt on a project ...
# detekt
l
Hello 👋 I want to setup detekt on a project with 400 modules and run it using a git hook on staged files only. So I used detekt cli, which works well except for rules using type resolution. The only way I've found is to use the gradle plugin. But unless I'm mistaken, I have to run it on every sub projects, which takes a long time. detekt cli was much faster and allows me to specify only a few files. I'd like to get close to detekt-cli performance with rules that use type resolution. I've also tried making a gradle task (detektAll) but it's the same as cli, the classpaths are missing. How can I speed up the task ? Or how can I retrieve relevant classpaths for detekt cli ? 🙂 Here is my configuration with gradle plugin:
Copy code
subprojects {
 apply {
  plugin("io.gitlab.arturbosch.detekt")
 }

 detekt {
  source.setFrom("src/main/kotlin", "src/main/java")

  buildUponDefaultConfig = true
  config.setFrom("$rootDir/detekt/config.yml")
  baseline = file("$projectDir/detekt/baseline.xml")
  autoCorrect = true
  parallel = true
  ignoreFailures = false
  buildUponDefaultConfig = true
  autoCorrect = true
  ignoredBuildTypes = ["release", "benchmarkDebug", "benchmarkRelease"]
  basePath = rootDir
 }

 dependencies {
  detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.23.7")
  detektPlugins("io.nlopez.compose.rules:detekt:0.4.17")
 }
}
âž• 1
b
Type resolution will always be way slower. It needs to generate the binding context and that's slow. Detekt with debug mode shows you were the time is expended. I would bet that the number of files is not relevant in the overall performance. Detekt gradle plugin doesn't force to recheck all the submodules. Only the ones with changes in their files or classpath. If you change the nullability in one module we need to recheck all the modules that depends on it because there may be now issues in those modules. I think that a commit hook with type resolution is not a good idea. It will be always slow. I think that your current setup + run type resolution on CI is the best approach.
l
Hello 🙂 Thanks for your answer. Indeed rules with type resolution are slower, but if I run detekt (without type resolution) using the detekt gradle plugin, it still takes 10 times longer than the cli. I've also tried to set specific files with 'include' but it doesn't have much impact on performance, even if it does check only the given files. I've done something like this, is there anything better to do?
Copy code
tasks.withType(Detekt).configureEach {
  project.property("input").split(",").each { include(it) }
}
b
10minutes longer? That's a lot. Sounds like a bug somewhere (configuration on your end or on detekt itself). Could you open an issue with the information that you have? A build scan would help a lot here. Also a way to reproduce it. About only including the changed files: I think that it only hurts the performance. You are changing the inputs of the task too much so gradle will never
UP TO DATE
or
FROM CACHE
. The number of files doesn't impact too much in the overall performance (if the modules aren't huge)
thank you color 1