aaschmid/gradle-cpd-plugin

Incorrect warning about ':cpdCheck' not being added to task graph in multi-project setup

ivansenic opened this issue · 11 comments

Hi,

I have a multi project setup where I define the cpd/cpdCheck properties via subprojects {} in the project.root.gradle:

allprojects {
    apply plugin: 'java'
    apply plugin: 'pmd'
    apply plugin: 'checkstyle'
    apply plugin: 'findbugs'
    apply plugin: 'net.saliman.cobertura'
    apply plugin: 'de.aaschmid.cpd'
    apply plugin: "me.champeau.gradle.jmh"

    apply from: file(propertiesFile.absolutePath)
    apply from: file(dependenciesFile.absolutePath)
}
...
subprojects {
    /**
     *  Task for the CPD.
     */
    cpd {
        skipLexicalErrors = true
        minimumTokenCount = 100
    }

    cpdCheck {
        // ignoring CPD failures on purpose
        ignoreFailures = true
        reports {
            xml {
                enabled = true
                destination = file("${buildQAAnalysisCPD}/main.xml")
            }
        }
    }

    task cpdHtmlReport << {
        ant.xslt(in: "${buildQAAnalysisCPD}/main.xml", style: cpdReportFile, out: "${buildQAAnalysisCPD}/../cpd.html")
    }
    cpdCheck.finalizedBy cpdHtmlReport
}

During the evaluation of the projects I get a warning from the cpd plugin that the cpdCheck task can not be added to the task graph due to the absence of the JavaBasePlugin. First of all, java plugin is used in all projects. Second, the task is absolutely correctly added as the dependency of the check task and executed correctly as well:

../gradlew check
WARNING: Due to the absence of JavaBasePlugin on root project 'inspectit.root' the task ':cpdCheck' could not be added to task graph and therefore will not be executed. SUGGESTION: add a dependency to task ':cpdCheck' manually to a subprojects 'check' task, e.g. to project ':inspectit.agent.java' using

    check.dependsOn(':cpdCheck')

or to root project 'inspectit.root' using

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

WARNING: Due to the absence of JavaBasePlugin on project ':inspectit.server' the task ':inspectit.server:cpdCheck' could not be added to task graph and therefore will not be executed. SUGGESTION: add a dependency to task ':inspectit.server:cpdCheck' manually to a subprojects 'check' task, e.g. to project ':inspectit.agent.java' using

    check.dependsOn(':inspectit.server:cpdCheck')

or to project ':inspectit.server' using

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

WARNING: Due to the absence of JavaBasePlugin on project ':inspectit.shared.all' the task ':inspectit.shared.all:cpdCheck' could not be added to task graph and therefore will not be executed. SUGGESTION: add a dependency to task ':inspectit.shared.all:cpdCheck' manually to a subprojects 'check' task, e.g. to project ':inspectit.agent.java' using

    check.dependsOn(':inspectit.shared.all:cpdCheck')

or to project ':inspectit.shared.all' using

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

WARNING: Due to the absence of JavaBasePlugin on project ':inspectit.shared.cs' the task ':inspectit.shared.cs:cpdCheck' could not be added to task graph and therefore will not be executed. SUGGESTION: add a dependency to task ':inspectit.shared.cs:cpdCheck' manually to a subprojects 'check' task, e.g. to project ':inspectit.agent.java' using

    check.dependsOn(':inspectit.shared.cs:cpdCheck')

or to project ':inspectit.shared.cs' using

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

WARNING: Due to the absence of JavaBasePlugin on project ':inspectit.ui.rcp' the task ':inspectit.ui.rcp:cpdCheck' could not be added to task graph and therefore will not be executed. SUGGESTION: add a dependency to task ':inspectit.ui.rcp:cpdCheck' manually to a subprojects 'check' task, e.g. to project ':inspectit.agent.java' using

    check.dependsOn(':inspectit.ui.rcp:cpdCheck')

or to project ':inspectit.ui.rcp' using

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

:inspectit.shared.all:compileJava UP-TO-DATE
:inspectit.shared.all:processResources UP-TO-DATE
:inspectit.shared.all:classes UP-TO-DATE
:inspectit.shared.all:jar UP-TO-DATE
:inspectit.agent.java:compileJava UP-TO-DATE
:inspectit.agent.java:processResources UP-TO-DATE
:inspectit.agent.java:classes UP-TO-DATE
:inspectit.agent.java:checkstyleMain UP-TO-DATE
:inspectit.agent.java:checkstyleHtmlReport
:inspectit.agent.java:cpdCheck UP-TO-DATE
:inspectit.agent.java:cpdHtmlReport
:inspectit.agent.java:findbugsMain UP-TO-DATE
:inspectit.agent.java:findbugsHtmlReport
:inspectit.agent.java:pmdMain UP-TO-DATE
:inspectit.agent.java:pmdHtmlReport
:inspectit.agent.java:instrument UP-TO-DATE
:inspectit.agent.java:copyCoberturaDatafile
:inspectit.shared.all:compileTestJava UP-TO-DATE
:inspectit.shared.all:processTestResources UP-TO-DATE
:inspectit.shared.all:testClasses UP-TO-DATE
:inspectit.agent.java:compileTestJava UP-TO-DATE
:inspectit.agent.java:processTestResources UP-TO-DATE
:inspectit.agent.java:testClasses UP-TO-DATE

Since this is the only warning in my build I would really like to get rid of it :). Can you maybe have a look on this?

Hi @ivansenic, hm ... this is very strange but hopefully I will have time during this or the next weekend to have a deeper look at it. As it is working, I hope this is sufficient for now. Otherwise, please let me know.
If you want to have it faster, you could help by creating a little reproducer on GitHub (or copy the build.gradle file content to an comment) ;-)

Unfortunately time is running and I have non for looking at this. Please be patient ...

Hi @ivansenic, thanks for the patience.

First, what I missed in my previous comments. I would suggest applying the CPD plugin only to the root project. It will automatically add all the Java, Groovy, Scala and so on sources to it and check it over the complete code base. This should also prevent the warning if I am correct.

Second, can you provide me your settings.gradle also as my manually generated one (with the information of the logs above) does not work properly. At least I cannot reproduce the behavior so far ... (but I am on it)

I also have no clue about your buildscript section.

On my machine the following works:

settings.gradle:

include 'inspectit.server', 'inspectit.shared.all', 'inspectit.shared.cs', 'inspectit.agent.java', 'inspectit.ui.rcp'

build.gradle:

buildscript {                                                                                                                                                                                  
    repositories {
        jcenter()
    }  

    dependencies {
        classpath 'de.aaschmid.gradle.plugins:gradle-cpd-plugin:0.5'
    }  
}

allprojects {
    apply plugin: 'java'
    apply plugin: 'pmd'
    apply plugin: 'checkstyle'
    apply plugin: 'findbugs'
//    apply plugin: 'net.saliman.cobertura'
//    apply plugin: 'de.aaschmid.cpd'
    apply plugin: 'cpd'
//    apply plugin: "me.champeau.gradle.jmh"

//    apply from: file(propertiesFile.absolutePath)
//    apply from: file(dependenciesFile.absolutePath)
}

subprojects {
    /**
     *  Task for the CPD.
     */
    cpd {
        skipLexicalErrors = true
        minimumTokenCount = 100
    }  

    cpdCheck {
        // ignoring CPD failures on purpose
        ignoreFailures = true
        reports {
            xml {
                enabled = true
                destination = file("main.xml")
            }  
        }  
    }  

    task cpdHtmlReport << {
//        ant.xslt(in: "main.xml", style: cpdReportFile, out: "../cpd.html")
    }  
    cpdCheck.finalizedBy cpdHtmlReport
}

Output:

% gradle check
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:checkstyleMain UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:checkstyleTest UP-TO-DATE
:cpdCheck UP-TO-DATE
:findbugsMain UP-TO-DATE
:findbugsTest UP-TO-DATE
:pmdMain UP-TO-DATE
:pmdTest UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:inspectit.agent.java:compileJava UP-TO-DATE
:inspectit.agent.java:processResources UP-TO-DATE
:inspectit.agent.java:classes UP-TO-DATE
:inspectit.agent.java:checkstyleMain UP-TO-DATE
:inspectit.agent.java:compileTestJava UP-TO-DATE
:inspectit.agent.java:processTestResources UP-TO-DATE
:inspectit.agent.java:testClasses UP-TO-DATE
:inspectit.agent.java:checkstyleTest UP-TO-DATE
:inspectit.agent.java:cpdCheck UP-TO-DATE
:inspectit.agent.java:cpdHtmlReport
:inspectit.agent.java:findbugsMain UP-TO-DATE
:inspectit.agent.java:findbugsTest UP-TO-DATE
:inspectit.agent.java:pmdMain UP-TO-DATE
:inspectit.agent.java:pmdTest UP-TO-DATE
:inspectit.agent.java:test UP-TO-DATE
:inspectit.agent.java:check UP-TO-DATE
:inspectit.server:compileJava UP-TO-DATE
:inspectit.server:processResources UP-TO-DATE
:inspectit.server:classes UP-TO-DATE
:inspectit.server:checkstyleMain UP-TO-DATE
:inspectit.server:compileTestJava UP-TO-DATE
:inspectit.server:processTestResources UP-TO-DATE
:inspectit.server:testClasses UP-TO-DATE
:inspectit.server:checkstyleTest UP-TO-DATE
:inspectit.server:cpdCheck UP-TO-DATE
:inspectit.server:cpdHtmlReport
:inspectit.server:findbugsMain UP-TO-DATE
:inspectit.server:findbugsTest UP-TO-DATE
:inspectit.server:pmdMain UP-TO-DATE
:inspectit.server:pmdTest UP-TO-DATE
:inspectit.server:test UP-TO-DATE
:inspectit.server:check UP-TO-DATE
:inspectit.shared.all:compileJava UP-TO-DATE
:inspectit.shared.all:processResources UP-TO-DATE
:inspectit.shared.all:classes UP-TO-DATE
:inspectit.shared.all:checkstyleMain UP-TO-DATE
:inspectit.shared.all:compileTestJava UP-TO-DATE
:inspectit.shared.all:processTestResources UP-TO-DATE
:inspectit.shared.all:testClasses UP-TO-DATE
:inspectit.shared.all:checkstyleTest UP-TO-DATE
:inspectit.shared.all:cpdCheck UP-TO-DATE
:inspectit.shared.all:cpdHtmlReport
:inspectit.shared.all:findbugsMain UP-TO-DATE
:inspectit.shared.all:findbugsTest UP-TO-DATE
:inspectit.shared.all:pmdMain UP-TO-DATE
:inspectit.shared.all:pmdTest UP-TO-DATE
:inspectit.shared.all:test UP-TO-DATE
:inspectit.shared.all:check UP-TO-DATE
:inspectit.shared.cs:compileJava UP-TO-DATE
:inspectit.shared.cs:processResources UP-TO-DATE
:inspectit.shared.cs:classes UP-TO-DATE
:inspectit.shared.cs:checkstyleMain UP-TO-DATE
:inspectit.shared.cs:compileTestJava UP-TO-DATE
:inspectit.shared.cs:processTestResources UP-TO-DATE
:inspectit.shared.cs:testClasses UP-TO-DATE
:inspectit.shared.cs:checkstyleTest UP-TO-DATE
:inspectit.shared.cs:cpdCheck UP-TO-DATE
:inspectit.shared.cs:cpdHtmlReport
:inspectit.shared.cs:findbugsMain UP-TO-DATE
:inspectit.shared.cs:findbugsTest UP-TO-DATE
:inspectit.shared.cs:pmdMain UP-TO-DATE
:inspectit.shared.cs:pmdTest UP-TO-DATE
:inspectit.shared.cs:test UP-TO-DATE
:inspectit.shared.cs:check UP-TO-DATE
:inspectit.ui.rcp:compileJava UP-TO-DATE
:inspectit.ui.rcp:processResources UP-TO-DATE
:inspectit.ui.rcp:classes UP-TO-DATE
:inspectit.ui.rcp:checkstyleMain UP-TO-DATE
:inspectit.ui.rcp:compileTestJava UP-TO-DATE
:inspectit.ui.rcp:processTestResources UP-TO-DATE
:inspectit.ui.rcp:testClasses UP-TO-DATE
:inspectit.ui.rcp:checkstyleTest UP-TO-DATE
:inspectit.ui.rcp:cpdCheck UP-TO-DATE
:inspectit.ui.rcp:cpdHtmlReport
:inspectit.ui.rcp:findbugsMain UP-TO-DATE
:inspectit.ui.rcp:findbugsTest UP-TO-DATE
:inspectit.ui.rcp:pmdMain UP-TO-DATE
:inspectit.ui.rcp:pmdTest UP-TO-DATE
:inspectit.ui.rcp:test UP-TO-DATE
:inspectit.ui.rcp:check UP-TO-DATE

BUILD SUCCESSFUL

Total time: 0.66 secs

Maybe I commented out too many lines in build.gradle ...

Hi Andreas,

I updated yesterday my branch containing the problem I described. You can have a look on it here: https://github.com/ivansenic/inspectIT/tree/INSPECTIT-1811. I moved now all the apply plugins to the

subprojects {
}

Now when I execute the build from the root project the error message is not there. But when I try any of the sub-projects the error messages are still there. Can it be that the changes that you did are actually a solution for it:

// apply plugin: 'de.aaschmid.cpd'
apply plugin: 'cpd'

I will have a look.

Still not working for me.. Maybe easiest is to pull my branch and check on your own.. Just go to any of the sub-projects and run the check task:

ise@ise-CELSIUS-H730:~/workspace/inspectIT/ivansenic-inspectit/inspectit.agent.java$ ../gradlew check
WARNING: Due to the absence of JavaBasePlugin on project ':inspectit.server' the task ':inspectit.server:cpdCheck' could not be added to task graph and therefore will not be executed. SUGGESTION: add a dependency to task ':inspectit.server:cpdCheck' manually to a subprojects 'check' task, e.g. to project ':inspectit.agent.java' using

    check.dependsOn(':inspectit.server:cpdCheck')

or to project ':inspectit.server' using

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

WARNING: Due to the absence of JavaBasePlugin on project ':inspectit.shared.all' the task ':inspectit.shared.all:cpdCheck' could not be added to task graph and therefore will not be executed. SUGGESTION: add a dependency to task ':inspectit.shared.all:cpdCheck' manually to a subprojects 'check' task, e.g. to project ':inspectit.agent.java' using

    check.dependsOn(':inspectit.shared.all:cpdCheck')

or to project ':inspectit.shared.all' using

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

WARNING: Due to the absence of JavaBasePlugin on project ':inspectit.shared.cs' the task ':inspectit.shared.cs:cpdCheck' could not be added to task graph and therefore will not be executed. SUGGESTION: add a dependency to task ':inspectit.shared.cs:cpdCheck' manually to a subprojects 'check' task, e.g. to project ':inspectit.agent.java' using

    check.dependsOn(':inspectit.shared.cs:cpdCheck')

or to project ':inspectit.shared.cs' using

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

WARNING: Due to the absence of JavaBasePlugin on project ':inspectit.ui.rcp' the task ':inspectit.ui.rcp:cpdCheck' could not be added to task graph and therefore will not be executed. SUGGESTION: add a dependency to task ':inspectit.ui.rcp:cpdCheck' manually to a subprojects 'check' task, e.g. to project ':inspectit.agent.java' using

    check.dependsOn(':inspectit.ui.rcp:cpdCheck')

or to project ':inspectit.ui.rcp' using

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

:inspectit.shared.all:compileJava UP-TO-DATE
:inspectit.shared.all:processResources UP-TO-DATE
:inspectit.shared.all:classes UP-TO-DATE
:inspectit.shared.all:jar
:inspectit.agent.java:compileJava
:inspectit.agent.java:processResources UP-TO-DATE
:inspectit.agent.java:classes
:inspectit.agent.java:checkstyleMain UP-TO-DATE
:inspectit.agent.java:checkstyleHtmlReport
:inspectit.agent.java:cpdCheck UP-TO-DATE
:inspectit.agent.java:cpdHtmlReport
:inspectit.agent.java:findbugsMain
:inspectit.agent.java:findbugsHtmlReport
:inspectit.agent.java:pmdMain
:inspectit.agent.java:pmdHtmlReport
:inspectit.agent.java:instrument SKIPPED
:inspectit.agent.java:copyCoberturaDatafile SKIPPED
:inspectit.shared.all:compileTestJava UP-TO-DATE
:inspectit.shared.all:processTestResources UP-TO-DATE
:inspectit.shared.all:testClasses UP-TO-DATE
:inspectit.agent.java:compileTestJava
:inspectit.agent.java:processTestResources UP-TO-DATE
:inspectit.agent.java:testClasses
:inspectit.agent.java:test
:inspectit.agent.java:generateCoberturaReport SKIPPED
:inspectit.agent.java:performCoverageCheck SKIPPED
:inspectit.agent.java:check

BUILD SUCCESSFUL

Thanks for your replies. I will have a detailed look later.

But what I meant with my previous comments, is that the CPD task is by default meant to be applied just on the root project to check the entire source code for duplicates. This would solve your problem if that fits your goals because than the cpdCheck can only be executed for the entire source code.

You btw. check the complete source code within all your subprojects without the warning. I think I have to adjust the documentation that every user can understand that ...

Hi Andreas,

Ok so it works without the warning if I just apply the plugin to the root project. Then I have (note the last line):

subprojects {
/**
     *  Task for the CPD.
     */
    cpd {
        skipLexicalErrors = true
        minimumTokenCount = 100
    }

    cpdCheck {
        // ignoring CPD failures on purpose
        ignoreFailures = true
        reports {
            xml {
                enabled = true
                destination = file("${buildQAAnalysisCPD}/main.xml")
            }
        }
    }

    task cpdHtmlReport << {
        ant.xslt(in: "${buildQAAnalysisCPD}/main.xml", style: cpdReportFile, out: "${buildQAAnalysisCPD}/../cpd.html")
    }
    cpdCheck.finalizedBy cpdHtmlReport
    check.dependsOn(':cpdCheck')
}

and it works without the warning. I think this is enough for me at this point 👍

Hi @ivansenic,

as you just apply it to the root project, you only need to configure it on the root project either and it will check all your source code of all your projects together to also find duplicates over module borders.

I created a fork of your project, adjusted it and created a pull request, see ivansenic/inspectIT#3 :-)

Two further tips which I would change:

Hi,

Thanks a lot.. I will your proposal..
Cheers..