kordamp-gradle-plugins icon indicating copy to clipboard operation
kordamp-gradle-plugins copied to clipboard

[detekt] config not recognized during aggregateDetekt

Open triplem opened this issue 4 years ago • 8 comments

Without a configFile for detekt, the build will fail on the aggregateDetekt-Taks, even if "ignoreFailures=false" is given in the root project. As a tester, I have cloned the kordamp-gradle-test-suite and adopted 03_kotlin_gradle_kotlin_dsl to show this issue in the master-branch.

https://github.com/triplem/kordamp-gradle-test-suite

For me it looks like the config of the root-project is not applied and merged with the config of the concrete project (which is empty in this case), if the config-file is empty.

triplem avatar Dec 21 '20 21:12 triplem

I just rechecked this, and as soon as I apply the "buildUponDefaultConfig = true" I receive an error, that there are missing "NewLineOnEndOfFile" Issues. The Build is interrupted and the config "ignoreFailures" is not recognized at all.

I have adopted the above mentioned test again.

Please try the following command:

./gradlew -p 03_kotlin_gradle_kotlin_dsl detekt aggregatedetekt

triplem avatar Dec 21 '20 21:12 triplem

I see. I think this may be a systemic problem with all code quality plugins as long as:

  • there's a child project that has a code quality plugin enabled (typically requires a config file).
  • the root project does not have a matching config file.

I think the best course of action is to fail the build the immediately with a message stating that there must be an explicit config file for the root project.

aalmiray avatar Dec 21 '20 22:12 aalmiray

Hm, I guess that the config file is only part of the problem. If I do run the "detekt" task, the file seems to be necessary and the build fails without it, even though config.quality.detekt.ignoreFailures is true. If there is a file, the tasks runs successfully but does not report any problems as well, meaning that detekt is running with just the stats. But the aggregateDetekt does fail the build even with the ignoreFailures is true and a config file is in the project.

But eg for detekt, a config file should not be strictly necessary, because the default task can run without such a file.

triplem avatar Dec 21 '20 23:12 triplem

Even if I disable detekt on the root project, it is run on a "gradlew check", which IMHO should not happen.

triplem avatar Dec 22 '20 09:12 triplem

The quality plugins are designed such that if a child project has the plugin enabled so does the parent as well, in order to provide aggregate capabilities. This can be turned off by setting aggregate = false on the root config.

aalmiray avatar Dec 22 '20 09:12 aalmiray

kk

triplem avatar Dec 22 '20 10:12 triplem

I've cloned the reproducer project and ran the following commands

gm -p 03_kotlin_gradle_kotlin_dsl :project1:effectiveSettings --section=quality
gm -p 03_kotlin_gradle_kotlin_dsl :project1:detektTaskSettings

The first command shows the effective configuration of the detekt DSL block, which is

quality:
    detekt:
        enabled: true
        ignoreFailures: true
        toolVersion: 1.14.2
        configFile: /private/tmp/kordamp-gradle-test-suite/03_kotlin_gradle_kotlin_dsl/config/detekt/detekt.yml
        parallel: false
        failFast: false
        buildUponDefaultConfig: false
        disableDefaultRuleSets: false
    sonar:
        enabled: true

Clearly ignoreFailures is set to true by default. The second command prints out all properties of the detekt task, and here we find a problem

    ignoreFailures: false
    ignoreFailuresProp$detekt_gradle_plugin: false

It does not matter which value is set on the DSL, it appears the io.gitlab.arturbosch.detekt.Detekt task type ignores all the time. The value is set at https://github.com/kordamp/kordamp-gradle-plugins/blob/master/plugins/detekt-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/detekt/DetektPlugin.groovy#L239

aalmiray avatar Jan 05 '21 21:01 aalmiray

Scratch that. ignoreFailures is always set to false for aggregateDetekt at https://github.com/kordamp/kordamp-gradle-plugins/blob/master/plugins/detekt-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/detekt/DetektPlugin.groovy#L218

I believe this was done when this task actually aggregated existing results from all other detekt tasks instead of running a distinct task with all aggregated sources as it is right now.

Also, without a config file at the root the aggregating task should be automatically disabled. This means there must be a config file no matter what, even if it's an skeleton one,

https://github.com/kordamp/kordamp-gradle-plugins/blob/master/plugins/detekt-gradle-plugin/src/main/groovy/org/kordamp/gradle/plugin/detekt/DetektPlugin.groovy#L215-L217

aalmiray avatar Jan 28 '21 18:01 aalmiray

Detekt plugin has been removed

aalmiray avatar Mar 31 '23 10:03 aalmiray