我想通过Gradle获得运行Checkstyle的输出作为HTML报告。
我在Checkstyle plugin documentation里什么也没找到。
我已经将以下内容添加到我的build.gradle
文件中。
checkstyleTask {
reports {
html {
destination "build/reports/checkstyle.html"
}
}
}
但这导致了
出错之处:评估根项目'MyProject‘时出现问题。
在根项目‘MyProject’上找不到参数build_1vu33nc0ekgtoo19jt e86o8o42$_run_closure8@1d8ee20的方法checkstyleTask()。
有没有办法使用Gradle生成Checkstyle HTML报告?
谢谢。
发布于 2013-12-04 05:34:44
下面是我在一个小项目中如何做到这一点:
checkstyleMain << {
ant.xslt(in: reports.xml.destination,
style: new File('config/checkstyle-noframes-sorted.xsl'),
out: new File(reports.xml.destination.parent, 'main.html'))
}
这要求您将checkstyle-noframes sorted.xsl文件存储在项目的config
目录中,该文件来自checksyle二进制发行版的contrib目录。
如果你能负担得起运行SonarQube服务器的费用,那么使用声纳插件会带来更好的用户体验。
编辑:如果存在违规,上述操作将不起作用。这在所有情况下都应该是:
task checkstyleHtml << {
ant.xslt(in: checkstyleMain.reports.xml.destination,
style: file('/config/checkstyle-noframes-sorted.xsl'),
out: new File(checkstyleMain.reports.xml.destination.parent, 'main.html'))
}
checkstyleMain.finalizedBy checkstyleHtml
发布于 2016-01-28 15:46:37
看来我去派对要迟到了。但仍然认为这可能会帮助其他人解决同样的问题。
Gradle 2.10支持html文件报告生成。只需确保在gradle-wrapper.properties
文件中正确配置了版本即可。
在此之后,在您的build.gradle
文件中,您应该具有如下所示的配置。
apply plugin: 'checkstyle'
checkstyle {
toolVersion = '6.4.1'
sourceSets = [sourceSets.main]
configFile = rootProject.file("config/checkstyle/checkstyle.xml");
showViolations = true
ignoreFailures = true
}
checkstyleTest {
enabled = false
}
tasks.withType(Checkstyle) {
reports {
html.destination rootProject.file("build/reports/checkstyle.html")
}
}
这里的config file
是包含您想要使用的检查样式模块的文件,而html.destination
是您希望生成html报告的位置。
发布于 2016-02-04 16:48:45
对于Gradle2.10,将以下代码添加到build.gradle
中
tasks.withType(Checkstyle) {
reports {
html.enabled = true
}
}
https://stackoverflow.com/questions/20361942
复制相似问题