detekt: `detektGenerateConfig` fails
Expected Behavior
If I run ./gradlew detektGenerateConfig
the configuration file should be created and gradle should not fail.
Observed Behavior
The file is created, but gradle fails: https://ge.detekt.dev/s/lpgeopyjrd46k/failure?expanded-stacktrace=WyIwIiwiMC03LTktMTEiXQ&focused-stack-frame=0-7-9-11-0
Steps to Reproduce
In this project:
rm config/detekt/detekt.yml
./gradlew detektGenerateConfig
Context
This is a long standing bug. I thought it was reported but I can’t find it.
Your Environment
- Version of detekt used: 1.20.0 / main
- Version of Gradle used (if applicable): 7.4.2
- Gradle scan link (add
--scan
option when running the gradle task): https://ge.detekt.dev/s/lpgeopyjrd46k - Link to your project (if it’s a public repository): https://github.com/detekt/detekt
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (16 by maintainers)
Just read your comment and I would like to add to your reasons:
First, con: generating many files in different modules as a result of “generate config” might mislead newcomers to think it’s “suggested” to not share the config between modules and need to configure each separately.
Second, pro: since there’s no behavior change, it can be improved upon easily in the future; reverted, etc.
Although this second one might be implicitly trivial 😃
It needs to load the
detektPlugin
dependencies as they contribute to the final config file that will be generatedThe problem is that you’re invoking multiple tasks here
detektGenerateConfig
. Not sure how to handle this, maybe the task should just not fail if the file already exists but just print a warning to the user?Still users will report that warnings are reported when invoking
./gradlew detektGenerateConfig
so it doesn’t really solve the underlying issue