我成功地添加Checkstyle到我Gradle的專案中build.gradle.kts:
plugins {
...
checkstyle
}
checkstyle {
toolVersion = "10.3.2"
isIgnoreFailures = false // Added this so that the tasks fail if CheckStyle errors are present.
}
我現在可以通過以下方式訪問 CheckStyle 的工具:
gradle checkstyleMaingradle checkstyleTest
它們都按預期作業,顯示警告并生成 HTML 報告。
我現在想讓任務在自身之前gradle run運行checkstyleMain任務,如果存在 CheckStyle 問題則失敗。
有沒有辦法做到這一點?到目前為止,我發現的唯一參考資料不是很清楚,并且是 for GroovyandAndroid而不是KotlinandJava build.gradle檔案。
uj5u.com熱心網友回復:
要使任務依賴于您需要使用的另一個任務dependsOn:
bootRun.dependsOn(checkstyleMain)
對于失敗的情況,error/warning可以使用以下配置checkstyle:
ignoreFailures = false
maxWarnings = 0
maxErrors = 0
uj5u.com熱心網友回復:
這對我有用:
checkstyle {
toolVersion = "10.3.2"
isIgnoreFailures = false
maxWarnings = 0
maxErrors = 0
}
val build = "build"
tasks[build].dependsOn("checkstyleMain")
gradle build如果在 中發現錯誤,現在將失敗checkstyleMain。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/503847.html
