Hey :wave: , I'm writing some Gradle plugins that ...
# detekt
s
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
If nothing works, read it from classpath and write it to file on plugin application.
🙏 1
g
You mean a baseline for Detekt? Or I don’t get what you’re trying to do exactly
s
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
Mmm I don’t think we support anything like that out of the box (i.e. shipping Detekt config alongside a module).
s
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
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
He hacked it 😄 Config is read from the file that his module writes on plugin application and points detect to.
☝️ 1
s
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
can't you put the yaml config in the root project and reference it by
rootProject.file("config.yml")
everywhere else?
s
Not afaik because the files of the
rootProject
will not be included in the Gradle Plugin's jar.
e
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
Do you have an example of something like this?
e
./gradlew detekt
succeeds in the project but will fail if you comment out
detektConfig("example.config:config")
s
Oh, interesting! Thank you for sharing 🙏 That looks indeed like what I need