Hi everyone! We are updating our base config rule...
# detekt
c
Hi everyone! We are updating our base config rules and for a lot of the former rule sets we were using
excludes: &generatedCode
to exclude generated code from each of the rules that apply. I thought there might be a way nowadays to exclude generated code from all rules so after looking into it, I found a closed issue about the topic: https://github.com/detekt/detekt/issues/4743 so I went with:
Copy code
detekt {
    source = files("src/main/kotlin", "src/test/kotlin", "src/androidTest/kotlin")
}
but that didn’t make it. I saw another dev asking about this about two months ago but I’m not sure it got resolved: https://kotlinlang.slack.com/archives/C88E12QH4/p1654877805110359 I also landed on another thread where Nicola brought up:
Yeah I believe the
exclude
has no effect because we changed how we collect the source sets.
You’ll have to exclude using a like a package path or so. What happens is that excluded are computed for relative paths that are provided by the sourcesset from AGP
I’m not sure I completely follow the implications of the changes. I could assume this is a generic issue for most of us. Any chance you could share how you deal with this, if that’s the case? Thanks in advance 🙏
The solution I went for was to use
excludes
at a Rule Set level:
Copy code
style:
  excludes: [ '**/build/**' ]
b
How is your configuration? Which gradle task do you run? I use a nearly vanilla configuration of detekt and I don’t run into this issue.
c
@Brais Gabin
How is your configuration?
What’s the context? What do you want to know? Our config is mostly based on yours. I don’t think there’s anything in the config that excludes generated code, is there? And I don’t expect to be able to configure that from the Gradle Plugin since Gradle works under
/src
which is outside the scope.
Which gradle task do you run?
Copy code
./gradlew detektBaselineMain
p
it started working for me, when I used correct gradle version, that is compatible with my detekt version 🤷‍♂️ Even exclude of build dir is not needed now. https://detekt.dev/docs/introduction/compatibility/