简体   繁体   中英

Gradle Unable to run checkstyle

I have a java project on my laptop and I am building it with gradle. All dependencies are in file system as I am off line most of the time when working on it. They are not too many anyway.

build.gradle:

repositories {
    flatDir {
        dirs "${rootDir}/lib/main", "${rootDir}/lib/test", "${rootDir}/lib/quality"
    }
}

ext.configDir = "${rootDir}/gradle/config"
ext.scriptsDir = "${rootDir}/gradle/scripts"

Now I need to add some quality checks against my code. I was lucky to get PMD checks working but not so lucky with checkstyle. The example from gradle distribution, the gradle in action book I read, the gradle documentation does not seem to be rocket science but I just cant get it to work which become very frustrating, especially that with ant that would have been a five minutes task. Anyway this is my gradle.build entry for checkstyle:

apply from: "${scriptsDir}/checkstyle.gradle"

and this is my checkstyle.gradle (partially shown):

apply plugin: 'checkstyle'

ext.checkstyleConfigDir = new File(configDir, "checkstyle")
ext.checkstyleReportsDir = new File(reportsDir, "checkstyle")
ext.xslStyleFile = new File(checkstyleConfigDir, "checkstyle-noframes.xsl")

checkstyle {
    toolVersion = '6.10.1'
    configFile = new File(checkstyleConfigDir, 'sun_checks.xml')
    ignoreFailures = true
    showViolations = true
}

checkstyleMain.doLast {
    def main = new File(checkstyleReportsDir, "main.xml")
    if (main.exists()) {
        ant.xslt(in: main, style: xslStyleFile, out: new File(checkstyleReportsDir, "main.html"))
    }
}

dependencies {
    checkstyle( 'com.puppycrawl.tools:checkstyle:6.10.1' )
}

However when running my build the checkstyle task fails like below:

* What went wrong:
Execution failed for task ':checkstyleMain'.
> java.lang.ClassNotFoundException: com.puppycrawl.tools.checkstyle.CheckStyleTask

Looking inside the checkstyle-6.10.1.jar I can see there is not such a class as com.puppycrawl.tools.checkstyle.CheckStyleTask but there is one called com.puppycrawl.tools.checkstyle.ant.CheckStyleAntTask instead and I suspect this is the one that gradle should invoke. However I have no idea about how to make gradle invoke that.

The only one suspition I have is that my toolVersion = '6.10.1' is not properly defined and gradle invokes using some default. However all gradle api documentation says about that is this: "String toolVersion The version of the code quality tool to be used."

So what I am doing wrong and how should I fix it.

Thank you in advance for your inputs.

You're running into a bug in Gradle ( GRADLE-3314 ). This issue is fixed in Gradle 2.7 which should be out soon. Would you mind verifying that the issue is resolved with the latest 2.7 release candiate?

You can grab Gradle 2.7-rc-2 from the gradle release candidate landing page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM