detekt / sonar-detekt

SonarQube plugin for Kotlin
https://detekt.dev
GNU Lesser General Public License v3.0
493 stars 52 forks source link

Sonar analysis fails because config file is not found in parent directory of root project #173

Open yachoor opened 1 year ago

yachoor commented 1 year ago

When analysing gradle project with submodules analysis fails for root project - the config file is being looked in a directory above project.

My project structure is:

project
├── app
│   └── build.gradle.kts
├── module1
│   └── build.gradle.kts
├── build.gradle.kts
├── config
│   └── detekt
│       └── detekt.yml
├── module2
│   └── build.gradle.kts
└── settings.gradle.kts

I set detekt.sonar.kotlin.config.path to config/detekt/detekt.yml, which works during analysis of app, module1 and module2, but fails for root project - I get an error: Configuration does not exist: <path-to-projects>\config\detekt\detekt.yml which is one directory above my project.

The logic in https://github.com/detekt/sonar-detekt/blob/cdb5924d02e38960c6cd58e4dca3235476f140d8/src/main/kotlin/io/gitlab/arturbosch/detekt/sonar/sensor/DetektConfiguration.kt#L95 and https://github.com/detekt/sonar-detekt/blob/cdb5924d02e38960c6cd58e4dca3235476f140d8/src/main/kotlin/io/gitlab/arturbosch/detekt/sonar/sensor/DetektConfiguration.kt#L98 seems wrong - if file does not exist or ends in .yml/.yaml resolve it in another directory, skipping valid existing files.