https://kotlinlang.org logo
#detekt
Title
# detekt
s

simon.vergauwen

02/09/2022, 3:44 PM
Hey 👋 , I'm writing some Gradle plugins that share a common setup between a bunch of projects, and I'm trying to share the baseline file between all projects as well. Does anyone know how you can add a
baselline.yml
to a Gradle plugin? When I add it to
src/resource
it's not working correctly 😞 And it seems I cannot configure all properties from the baseline programmatically, or am I looking in the wrong place?
b

Big Chungus

02/09/2022, 3:49 PM
If nothing works, read it from classpath and write it to file on plugin application.
🙏 1
g

gammax

02/09/2022, 4:15 PM
You mean a baseline for Detekt? Or I don’t get what you’re trying to do exactly
s

simon.vergauwen

02/09/2022, 4:22 PM
Sorry, I meant the config file. I fixed it by following @Big Chungus's suggestion and copying the
config.yml
from the Gradle's plugin
src/resource
to the downstream project
build
folder and referencing that from the common Gradle plugin. The goal is to share the same Detekt configuration across all microservices so we can keep code aligned across all codebases.
g

gammax

02/09/2022, 4:24 PM
Mmm I don’t think we support anything like that out of the box (i.e. shipping Detekt config alongside a module).
s

simon.vergauwen

02/09/2022, 4:25 PM
It's working for now. Ideally (for me) the configuration would be exposed so it can be configured completely from Gradle, but I'm not familiar with the internals of Detekt.
g

gammax

02/09/2022, 4:26 PM
mmm 🤔 AFAIK, we don’t support (different/multiple) config for different modules. What do you mean with “it’s working for now”. You built something on top?
b

Big Chungus

02/09/2022, 4:27 PM
He hacked it 😄 Config is read from the file that his module writes on plugin application and points detect to.
☝️ 1
s

simon.vergauwen

02/09/2022, 4:31 PM
we don’t support (different/multiple) config for different modules.
That's not what I'm doing. We have a common Gradle plugin that configures Detekt with a common
config
for all modules in all projects where we consume the plugin. In order for the project to configure detekt, it needs access to the
config.yml
file. So I'm copying it from the Gradle plugin
src/resource
to the projects
build
folder.
e

ephemient

02/13/2022, 11:42 AM
can't you put the yaml config in the root project and reference it by
rootProject.file("config.yml")
everywhere else?
s

simon.vergauwen

02/17/2022, 10:23 AM
Not afaik because the files of the
rootProject
will not be included in the Gradle Plugin's jar.
e

ephemient

02/17/2022, 2:53 PM
oh you're publishing a binary plugin?
I think you should publish your config files as a separate artifact. then your plugin can create a configuration with that dependency, add it to task inputs, and let Gradle handle everything else
🤔 1
s

simon.vergauwen

02/17/2022, 2:54 PM
Do you have an example of something like this?
e

ephemient

02/17/2022, 3:29 PM
./gradlew detekt
succeeds in the project but will fail if you comment out
detektConfig("example.config:config")
s

simon.vergauwen

02/17/2022, 3:40 PM
Oh, interesting! Thank you for sharing 🙏 That looks indeed like what I need
2 Views