[英]Generate Checkstyle HTML report with Gradle
我想通過Gradle將Checkstyle的輸出作為HTML報告。
我在Checkstyle插件文檔中找不到任何內容 。
我已將以下內容添加到build.gradle
文件中。
checkstyleTask {
reports {
html {
destination "build/reports/checkstyle.html"
}
}
}
但這產生了
出了什么問題:評估根項目'MyProject'時出現問題。
無法在根項目“MyProject”上找到參數[build_1vu33nc0ekgtoo19jt e86o8o42 $ _run_closure8 @ 1d8ee20]的方法checkstyleTask()。
有沒有辦法使用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-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
看起來我遲到了。 但仍然發布這種想法,它可能會幫助其他人有同樣的問題。
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
是包含您要使用的checkstyle模塊的文件, html.destination
是您希望生成html報告的位置。
對於Gradle 2.10,將以下代碼添加到build.gradle
:
tasks.withType(Checkstyle) {
reports {
html.enabled = true
}
}
這是一個插件,可以輕松設置checkstyle。 它會根據您的喜好自動為checkstyle設置所有必需的配置,並最終生成HTML報告。
您需要做的就是在build.gradle
添加幾行,就是這樣。 無需創建單獨的xml文件。
該插件名為estilo 。 您可以在此處找到有關如何使用它的更多詳細信息 - https://github.com/anshulverma/gradle-estilo-plugin
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.