eoinzy
eoinzy

Reputation: 2242

FindBugs - Share bug settings between eclipse and maven

I'm hoping this is a simple enough question.

I have FindBugs working in Eclipse. I also have it working in Maven. However, if I see a bug that is either a false positive, or too mild, or quite simply isn't going to be fixed, then I will ignore it in Eclipse. This then leads to a problem where Maven still reports the bug. This is not ideal. Technically speaking I could probably edit the Maven config to ignore certain bugs, but that seems inefficient. Also, there will be a team of people working on this project so I will need to eventually find a solution where the bug settings are stored in SVN, or on a network drive.

But anyway, I think I have found the folder where the eclipse settings related to these bugs are stored: <ECLIPSE_WORKSPACE>/.metadata/.plugins/edu.umd.cs.findbugs.plugin.eclipse

Is it possible to point Maven at this same file during a build? Or actually, is it possible to extract this to a separate location, eg on the network, and then point both eclipse and maven at it?

Any help appreciated. Thanks.

Upvotes: 3

Views: 638

Answers (1)

RJo
RJo

Reputation: 16301

You can add a exclude filter file to you maven configuration:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>findbugs-maven-plugin</artifactId>
    <version>${findbugs-maven-plugin.version}</version>
    <configuration>
        <excludeFilterFile>path/to/excludes.xml</excludeFilterFile>
    </configuration>
</plugin>

The configuration file looks like this. The following will match SE_BAD_FIELD warning from findbugs from all classes inside my.package. See more here.

<FindBugsFilter>
  <Match>
    <Package name="~my.package.*"/>
    <Bug pattern="SE_BAD_FIELD"/>
  </Match>
</FindBugsFilter>

You can then add the same filter file to Eclipse FindBugs plugin from Window -> Preferences -> Java -> FindBugs -> Filter Files -> Exclude filter files -> Add..

Upvotes: 3

Related Questions