使用Gradle生成Checkstyle HTML报告 [英] Generate Checkstyle HTML report with Gradle

查看:318
本文介绍了使用Gradle生成Checkstyle HTML报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我没有发现任何东西在 Checkstyle插件文档



我已将以下内容添加到我的 build.gradle 文件中。


$ b

  checkstyleTask {
reports {
html {
destinationbuild / reports / checkstyle.html
}
}
}

但是这产生了


出了什么问题:评估根项目'MyProject'时出现问题。


$ b


无法找到方法checkstyleTask()for参数[build_1vu33nc0ekgtoo19jt e86o8o42 $ _run_closure8 @ 1d8ee20] on root
project'MyProject'。



有没有办法使用Gradle生成Checkstyle HTML报表?



谢谢。

解决方案

以下是我在一个小型项目中的工作方式:

  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二进制发行版的contrib目录中的checkstyle-noframes-sorted.xsl文件存储在项目的 config 目录中。



如果您可以负担运行SonarQube服务器,使用sonar插件可以带来更好的用户体验。

编辑:上面如果存在违规行为将无法使用。这应该在所有情况下:

 任务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


I'd like to get the output of running Checkstyle via Gradle as an HTML report.

I've found nothing in the Checkstyle plugin documentation.

I've added the following to my build.gradle file.

checkstyleTask {
    reports {
        html {
            destination "build/reports/checkstyle.html"
        }
    }
}

but this yielded

What went wrong: A problem occurred evaluating root project 'MyProject'.

Could not find method checkstyleTask() for arguments [build_1vu33nc0ekgtoo19jt e86o8o42$_run_closure8@1d8ee20] on root project 'MyProject'.

Is there a way to generate Checkstyle HTML reports using Gradle?

Thanks.

解决方案

Here's how I do it in a smal project of mine:

checkstyleMain << {
    ant.xslt(in: reports.xml.destination,
             style: new File('config/checkstyle-noframes-sorted.xsl'),
             out: new File(reports.xml.destination.parent, 'main.html'))
}

This requires that you store the checkstyle-noframes-sorted.xsl file, from the contrib directory of the checksyle binary distribution, in the config directory of your project.

If you can afford running a SonarQube server, using the sonar plugin leads to a much better user experience, though.

EDIT: The above won't work if there are violations. This should in all cases:

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

这篇关于使用Gradle生成Checkstyle HTML报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆