You are correct by adding ignoreFailures=true to prevent the task from crashing. Therefore, this parameter should be used and should be checked later if errors are detected.
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
You can find a complete and working example here. To make sure that it works, delete the incorrect.java file - then no errors were found and - no exception was thrown.
Opal
source share