简体   繁体   English

如何配置FindBugs maven插件以仅检查@Nonnull之类的注释违规?

[英]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. 我已经实现了这个问题的答案,因此@Nonnull违规使构建失败。 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? 我如何配置findbugs 关心findbugs注释?

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. 我可能会接受一个答案,告诉我如何在不使用maven插件的情况下完成它,因为我想我可以弄清楚如何将其转换为插件可以使用的东西。

Here's the findbugs maven configuration I use: 这是我使用的findbugs maven配置:

<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. findbugs-exclude.xml文件位于我的项目根目录中(与pom.xml相同 - 我应该把它放在更好的位置),并配置我想忽略的findbugs问题。 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 有关在findbugs手册中配置findbugs过滤器文件的更多信息

Also nore that you could change the findbugs maven plugin to only include certain filters using this instead of excludeFilterFile : 另外,您可以将findbugs maven插件更改为仅使用此而不是excludeFilterFile包含某些过滤器:

<includeFilterFile>findbugs-include.xml</includeFilterFile>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM