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

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (16 by maintainers)

Most upvoted comments

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 😃

🤔 Why does it need the plugin applied? Isn’t it reading from the classpath of the build?

It needs to load the detektPlugin dependencies as they contribute to the final config file that will be generated

If I run ./gradlew detektGenerateConfig the configuration file should be created and gradle should not fail.

The 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