Gradle无法运行checkstyle

时间:2015-09-07 19:25:38

标签: gradle checkstyle

我的笔记本电脑上有一个java项目,我用gradle构建它。 所有依赖项都在文件系统中,因为我在处理它时大部分时间都在离线。反正他们并不是太多。

的build.gradle:

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

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

现在我需要为我的代码添加一些质量检查。我很幸运能够通过checkstyle检查PMD检查,但不是那么幸运。 gradle分发的例子,我读过的动作书中的gradle,gradle文档似乎不是火箭科学,但是我不能让它工作变得非常令人沮丧,特别是那些本来是五分钟任务的蚂蚁。无论如何,这是checkstyle的 gradle.build 条目:

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

这是我的 checkstyle.gradle (部分显示):

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' )
}

但是,在运行构建时,checkstyle任务会失败,如下所示:

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

在checkstyle-6.10.1.jar中查看我可以看到没有com.puppycrawl.tools.checkstyle.CheckStyleTask这样的类,但有一个名为com.puppycrawl.tools.checkstyle.ant.CheckStyleAntTask,而我怀疑这是gradle应该调用的类。但是我不知道如何让gradle调用它。

我唯一怀疑的是我的toolVersion = '6.10.1'没有正确定义,并且gradle使用默认调用。但是,所有gradle api文档都说明了这一点:" String toolVersion要使用的代码质量工具的版本。"

所以我做错了,应该如何解决。

提前感谢您的意见。

1 个答案:

答案 0 :(得分:5)

您正在Gradle中遇到错误(GRADLE-3314)。 Gradle 2.7中已修复此问题,该问题应该很快就会出来。您是否介意使用最新的2.7版本来验证问题是否已解决?

您可以从gradle release candidate着陆页抓取Gradle 2.7-rc-2。

相关问题