Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I configure the FindBugs maven plugin to only check for annotation violations like @Nonnull?

I've implemented the answer from this question to make it so @Nonnull violations make the build fail. But the problem is, this is finding lots and lots of other bugs that I don't want to deal with yet. I've looked at the manual, and there's no section that jumps out at me as a, "Here's how you configure what to check for" chapter.

To me it seems like it should be in here, but the number of options don't seem nearly comprehensive enough. How would I configure findbugs to only care about the findbugs annotations?

I'll probably accept an answer that tells me how to do it without using the maven plugin because I think I can figure out how to translate that into something the plugin can use.

like image 799
Daniel Kaplan Avatar asked May 08 '14 18:05

Daniel Kaplan


People also ask

How do you generate FindBugs reports?

To generate the FindBugs report as part of the Project Reports, add the FindBugs plugin in the <reporting> section of your pom. xml. Then, execute the site plugin to generate the report.


1 Answers

Here's the findbugs maven configuration I use:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>findbugs-maven-plugin</artifactId>
    <version>2.4.0</version>
    <configuration>
        <excludeFilterFile>findbugs-exclude.xml</excludeFilterFile>
        <findbugsXmlOutput>true</findbugsXmlOutput>
        <xmlOutput>true</xmlOutput>
    </configuration>
</plugin>

The findbugs-exclude.xml file is in my project root directory (same level as pom.xml - I should probably put it somewhere better), and it configures what findbugs issues I want to ignore. Here's what's in my exclude file:

<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
    <Match>
        <Bug pattern="EI_EXPOSE_REP,EI_EXPOSE_REP2"/>
    </Match>
    <Match>
        <Package name="com.mypackage.something"/>
    </Match>
</FindBugsFilter>

There's more info about configuring the findbugs filter files in the findbugs manual

Also nore that you could change the findbugs maven plugin to only include certain filters using this instead of excludeFilterFile:

<includeFilterFile>findbugs-include.xml</includeFilterFile>
like image 97
John Farrelly Avatar answered Sep 22 '22 21:09

John Farrelly