问题
I am using Gradle FindBugs Plugin. How can I print reported bugs to console? PMD plugin has a consoleOutput property. Is there a similar property for FindBugs?
回答1:
As you can see here there's no such property or configuration possibility for FindBugs plugin. However it seems that the plugin can be customized in some way. E.g. by parsing and displaying the results.
See here and here.
回答2:
This is rudimentary ... but it's a start
task checkFindBugsReport << {
def xmlReport = findbugsMain.reports.xml
if (!xmlReport.destination.exists()) return;
def slurped = new XmlSlurper().parse(xmlReport.destination)
def report = ""
slurped['BugInstance'].eachWithIndex { bug, index ->
report += "${index + 1}. Found bug risk ${bug.@'type'} of category ${bug.@'category'} "
report += "in the following places"
bug['SourceLine'].each { place ->
report += "\n ${place.@'classname'} at lines ${place.@'start'}:${place.@'end'}"
}
}
if (report.length() > 1) {
logger.error "[FINDBUGS]\n ${report}"
}
}
findbugsMain.finalizedBy checkFindBugsReport
回答3:
You can do that with Violations Gradle Plugin. It is configured with patterns to identify report files and to run after check
. It will
- Accumulate all static code analysis tools into a unified report.
- Print it to the build log.
- Optionally fail the build if there are too many violations.
回答4:
Findbugs/Spotbugs come with a class that can run after analysis, read an xml report and print to text/html. It is included in the findbugs/spotbugs.jar file.
<java classname="edu.umd.cs.findbugs.PrintingBugReporter" fork="true">
<arg value="${build.dir}/findbugs/findbugs-test-report.xml"/>
<classpath path="${spotbugs.home}/lib/spotbugs.jar"/>
</java>
Which is same as running
java -cp path/to/spotbugs.jar edu.umd.cs.findbugs.PrintingBugReporter path/to/findbugs-report.xml
It has an -html
option that will render html.
It should be feasible to achieve the same in gradle/maven.
来源:https://stackoverflow.com/questions/28982149/how-can-i-print-reported-bugs-to-console-in-gradle-findbugs-plugin