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?
How can I print reported bugs to console in gradle findbugs plugin?
is your question answered? –
Nagging
So, you suggest that parse the report and print it, am I right? –
Shelve
It seems that this is the only workaround for now. See my updated answer. –
Nagging
My only purpose to print is to make easy to go line, which is reported by findbugs. I may use the ide plugin, which works perfect for this purpose but it is needed to be done this way unfortunately. I think I may sync the includefilter files of both ide and project config file. –
Shelve
It seems that an IDE plugin will suit your needs perfectly. –
Nagging
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.
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
can you share plugin dependencies also –
Shortcake
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.
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.
© 2022 - 2024 — McMap. All rights reserved.