aaschmid / gradle-cpd-plugin

Gradle plugin to find duplicate code using PMDs copy/paste detection (= CPD).
Apache License 2.0
96 stars 12 forks source link

Wrongly displayed WARNING that `cpdCheck` is not part of the task graph #37

Closed isuPatches closed 5 years ago

isuPatches commented 5 years ago

Hey there, I'm having some trouble with the 1.3 version. I have an Android library and don't understand how to fix this:

WARNING: Due to the absence of 'LifecycleBasePlugin' on project ':wisefy'
the provider(task cpdCheck, class de.aaschmid.gradle.plugins.cpd.Cpd) could not be added to task graph and therefore will not be executed.
SUGGESTION: add a dependency to cpdCheck manually to a subprojects 'check'
task, e.g. to project ':wisefy' using

    check.dependsOn('cpdCheck')

or to project ':wisefy' using

    project(':wisefy') {
        plugins.withType(LifecycleBasePlugin) { // <- just required if 'java' plugin is applied within subproject
            check.dependsOn(cpdCheck)
        }
    }
aaschmid commented 5 years ago

This is indeed strange.

Reason: Until version 1.2 the cpdCheck was attached while JavaBasePlugin was applied. In 1.3 I attached that behavior to LifecycleBasePlugin. This should not change anything since JavaBasePlugin applies BasePlugin which applies LifecycleBasePlugin ...

@isuPatches: Thanks for reporting, just checked out your referenced project and can perfectly reproduce the behavior. Working on understanding why it fails ...

aaschmid commented 5 years ago

Good news @isuPatches: cpdCheck is executed even if the above mentioned warning is shown.

So this issues drills down to an incorrect warning. Do you agree?

My output on ./gradlew build:

% gw --console plain build

> Configure project :
[...]
> Configure project :wisefy
[...]
WARNING: Due to the absence of 'LifecycleBasePlugin' on project ':wisefy'
the provider(task cpdCheck, class de.aaschmid.gradle.plugins.cpd.Cpd) could not be added to task graph and therefore will not be executed.
SUGGESTION: add a dependency to cpdCheck manually to a subprojects 'check'
task, e.g. to project ':wisefy' using

    check.dependsOn('cpdCheck')

or to project ':wisefy' using

    project(':wisefy') {
        plugins.withType(LifecycleBasePlugin) { // <- just required if 'java' plugin is applied within subproject
            check.dependsOn(cpdCheck)
        }
    }

> Task :wisefy:preBuild UP-TO-DATE
[...]
> Task :wisefy:cpdCheck FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':wisefy:cpdCheck'.
> CPD found duplicate code. See the report at [...]/WiseFy/wisefy/build/reports/cpd/cpdCheck.xml
[...]
isuPatches commented 5 years ago

👍 Yes, that's the same behavior I'm seeing locally. Thanks for the quick investigation!

aaschmid commented 5 years ago

Found the reason: While switching to TaskProvider in order to configuration avoidance, I do no longer have the actual task and I am assuming that CPD plugin is always applied on the root project. Latter could be reasonable because Copy-Paste-Detection should be applied to the whole (main) source code.