gpt4 book ai didi

gradle - 如何编写自定义的 gradle 任务以不忽略 Findbugs 违规但在分析完成后失败

转载 作者:行者123 更新时间:2023-12-04 23:48:38 24 4
gpt4 key购买 nike

我想编写这样一个 gradle 任务(使用 Findbugs 插件),如果发现任何 Findbugs 违规,它就会失败 但只有在完成分析后 .如果我这样做 ignoreFailures=true该任务根本不会失败,如果我将其设为 false,一旦发现第一个问题,该任务就会失败。我希望任务执行完整的分析,并且只有在发现任何违规的情况下才会在完成后失败。

最佳答案

你说得对,添加 ignoreFailures=true将防止任务失败。因此,应使用此选项,如果发现错误,应稍后检查。

这个脚本完成了这项工作:

apply plugin: 'java'
apply plugin: 'findbugs'

repositories {
mavenCentral()
}

findbugs {
ignoreFailures = true
}

task checkFindBugsReport << {
def xmlReport = findbugsMain.reports.xml
def slurped = new XmlSlurper().parse(xmlReport.destination)
def bugsFound = slurped.BugInstance.size()
if (bugsFound > 0) {
throw new GradleException("$bugsFound FindBugs rule violations were found. See the report at: $xmlReport.destination")
}
}

findbugsMain.finalizedBy checkFindBugsReport

Here可以找到完整的工作示例。要查看它是否有效,请删除 incorrect.java文件 - 然后没有发现错误并且 - 不会抛出异常。

关于gradle - 如何编写自定义的 gradle 任务以不忽略 Findbugs 违规但在分析完成后失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28069712/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com