java - 如何将 FindBugs maven 插件配置为仅检查 @Nonnull 等注释违规?

标签 java maven findbugs

我已经实现了 this question 的答案使 @Nonnull 违规使构建失败。但问题是,这会发现很多我不想处理的其他错误。我看过 the manual ,并且没有任何部分像“这是您配置要检查的内容”一章那样突然出现在我面前。

对我来说好像是it should be in here ,但选项的数量似乎还不够全面。我如何将 findbugs 配置为关心 findbugs 注释?

我可能会接受告诉我如何在不使用 maven 插件的情况下执行此操作的答案,因为我认为我可以弄清楚如何将其转换为插件可以使用的内容。

最佳答案

这是我使用的 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>

findbugs-exclude.xml 文件位于我的项目根目录中(与 pom.xml 处于同一级别 - 我可能应该将其放在更好的地方),它配置了我想忽略的 findbugs 问题。这是我的排除文件中的内容:

<?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>

有关配置 findbugs 过滤器文件的更多信息 in the findbugs manual

另外请注意,您可以更改 findbugs maven 插件以仅包含某些使用此过滤器而不是 excludeFilterFile 的过滤器:

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

关于java - 如何将 FindBugs maven 插件配置为仅检查 @Nonnull 等注释违规?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23550195/

相关文章:

character-encoding - JCA 部署描述符 (ra.xml) 字符编码应该是什么?

java - FindBugs 2.0 中弃用的注释

java - 如何计算有符号随机整数的绝对值

java - Spinner 值自动更新到位置 0,该位置从 firebase 获取数据

maven - 无论 Maven 生命周期如何,如何合并 2 个 jacoco 覆盖率报告(.exec 文件)

java - 使用压缩的缓冲图像转换

maven - 雅 cocoa - "Caused by: java.lang.ClassNotFoundException: org.jacoco.agent.rt.internal_6da5971.Offline"

android - 如何下载带有所有依赖项的 Artifact ?

java - 生成带有内置 XSD 限制的 Java 类

java - 如何在休息 Controller 中抛出异常