I want to write such a gradle task (using the Findbugs plugin) which fails if any Findbugs violations are found but only after completing the analysis. If I do ignoreFailures=true
the task won't fail at all and if I make it false the task fails as soon as the first issue is found. I want the task to perform a complete analysis and fail only after it's done if any violations are found.
You're right, adding ignoreFailures=true
will prevent task from failing. Thus this option should be used and it should be checked later on if bugs were found.
This script does the job:
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 complete and working example can be found. To see if it works remove incorrect.java
file - then no bugs are found and - no exception is thrown.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With