Gradle 无法 运行 checkstyle
Gradle Unable to run 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"
现在我需要对我的代码添加一些质量检查。我很幸运能够使用 PMD 检查,但使用 checkstyle 就没那么幸运了。来自 gradle 发行版的示例,我读过的 gradle in action 书,gradle 文档似乎不是火箭科学,但我就是无法让它工作,这变得非常令人沮丧,尤其是对于 ant 来说,这将是一个五分钟的任务。无论如何,这是我的 gradle.build checkstyle 条目:
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
这样的 class 但有一个叫做 com.puppycrawl.tools.checkstyle.ant.CheckStyleAntTask
,我怀疑这是 gradle 应该调用的那个。但是我不知道如何让 gradle 调用它。
我唯一的怀疑是我的 toolVersion = '6.10.1'
没有正确定义并且 gradle 使用一些默认值调用。然而,所有 gradle api 文档都是这样说的:"String toolVersion The version of the code quality tool to be used."
所以我做错了什么,我应该如何解决它。
提前感谢您的意见。
您 运行 遇到了 Gradle (GRADLE-3314) 中的错误。此问题已在 Gradle 2.7 中修复,应该很快就会发布。您介意验证问题是否已通过最新的 2.7 候选版本解决吗?
您可以从 gradle release candidate 着陆页获取 Gradle 2.7-rc-2。
我的笔记本电脑上有一个 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"
现在我需要对我的代码添加一些质量检查。我很幸运能够使用 PMD 检查,但使用 checkstyle 就没那么幸运了。来自 gradle 发行版的示例,我读过的 gradle in action 书,gradle 文档似乎不是火箭科学,但我就是无法让它工作,这变得非常令人沮丧,尤其是对于 ant 来说,这将是一个五分钟的任务。无论如何,这是我的 gradle.build checkstyle 条目:
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
这样的 class 但有一个叫做 com.puppycrawl.tools.checkstyle.ant.CheckStyleAntTask
,我怀疑这是 gradle 应该调用的那个。但是我不知道如何让 gradle 调用它。
我唯一的怀疑是我的 toolVersion = '6.10.1'
没有正确定义并且 gradle 使用一些默认值调用。然而,所有 gradle api 文档都是这样说的:"String toolVersion The version of the code quality tool to be used."
所以我做错了什么,我应该如何解决它。
提前感谢您的意见。
您 运行 遇到了 Gradle (GRADLE-3314) 中的错误。此问题已在 Gradle 2.7 中修复,应该很快就会发布。您介意验证问题是否已通过最新的 2.7 候选版本解决吗?
您可以从 gradle release candidate 着陆页获取 Gradle 2.7-rc-2。