我有 2 个项目正在使用 FindBugs
插件 maven
识别错误。我也在使用@SuppressFBWarnings
注释以忽略特定错误。
在第一个项目中,我将依赖项添加到 pom.xml 中,findbugs 报告和注释都工作正常。在第二个项目中,生成了报告,但它仍然标识了我使用注释抑制的错误。
我跑mvn clean install site
在我的机器上的构建文件夹中生成报告。
我提到的 2 个项目中的每一个都有子项目,在其子目录中都有自己的 pom.xml 文件,因此在父目录中,我也有一个 pom.xml。此目录布局在两个主项目中的镜像完全相同。
这是我添加到<reporting>
下的父pom中的XML标签:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<xmlOutput>true</xmlOutput>
<findbugsXmlOutput>true</findbugsXmlOutput>
<fork>true</fork>
<threshold>Low</threshold>
<effort>Min</effort>
</configuration>
</plugin>
此外,在同一个父 pom 中,我将其添加到 <dependencyManagement><dependencies>
部分:
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>2.0.1</version>
</dependency>
这在两个主要项目 pom 中都是相同的。
现在,在我实际使用 @SuppressFBWarnings
的子项目中注释,并且仅在该特定子项目中,我在 <dependencies>
下有此注释:
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>2.0.1</version>
</dependency>
此外,这也反射(reflect)在其他工作项目中。我是直接复制粘贴的。
一个项目运行完美,我可以成功抑制误报。另一个项目完全忽略了@SuppressFBWarnings
注释,我似乎无法修复它。
我在这里缺少什么吗?
我认为如果没有找到注释,它不会给出错误,而是会忽略它?我如何判断是否未找到?
希望这是一个简单的修复。
谢谢。
最佳答案
@SuppressFBWarnings 是在版本 3 中随注释一起引入的。这就是为什么它应该如下所示:
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>3.0.1</version>
</dependency>
关于maven忽略findbugs抑制FBWarnings注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14964048/