Is there a way to overwrite only a few config properties for detekt, and preserve most props from default-detekt-config.yml
?

- 2,084
- 7
- 29
- 43
1 Answers
Yes there is!
I assume you are using the gradle-plugin
. Actually you can specify more than one config file in the config
property:
gradle
detekt {
defaultProfile {
...
# config = "path/to/default.yml, path/to/my/config.yml"
config = files(file("default-config"), file("my-config"))
}
}
The config property can be a FileCollection, a File or just a String with comma-separated path entries. Make sure that the default configuration file is listed first. Now you can override each rule setting and property in your custom detekt configuration file.
Take a look how we @detekt configure two configs here https://github.com/arturbosch/detekt/blob/master/build.gradle.kts#L206 and this is how our custom config file looks like: https://github.com/arturbosch/detekt/blob/master/reports/failfast.yml.
Edit: If you are using just the CLI, you may write java -jar detekt.jar --config "first-config.yml,second-config.yml" ....

- 3,177
- 2
- 23
- 33

- 46
- 3
-
Is there any way just to overwrite one property? e.g. via simple variables in gradle? – Torsten Jan 29 '19 at 12:00
-
1Unfortunately not. The yaml file is the only place where rules get configured. However with https://github.com/arturbosch/detekt/pull/1417 merged in the next version, you will be able to just override the properties you want without copy-pasting the whole default configuration file. – Artur Bosch Jan 30 '19 at 22:30
-
hoorray, it works! Thank you so much for pull 1417 :-) – Torsten Feb 19 '19 at 10:23
-
maybe you can provide a new (official) answer in this thread? – Torsten Feb 19 '19 at 10:40