21 java findbugs include spotbugs
要导入什么来使用SuppressFBWarnings?我通过help/install新软件安装了findbugs插件当我输入import edu.时,我无法通过ctrl空间来获取选项.
例
try {
String t = null;
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
value="NP_ALWAYS_NULL",
justification="I know what I'm doing")
int sl = t.length();
System.out.printf( "Length is %d", sl );
} catch (Throwable e) {
...
}
Run Code Online (Sandbox Code Playgroud)
有错误"edu无法解析为某种类型"
bar*_*uin 21
要使用FindBugs注释,您需要在类路径中包含FindBugs发行版中的annotations.jar和jsr305.jar.如果您确定@SuppressFBWarnings只需要注释(而不是其他注释),那么单独使用annotations.jar就足够了.
您可以在FindBugs发行版的lib文件夹中找到两个JAR .
如果您使用Maven:
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
如果您使用的是Gradle:
dependencies {
compileOnly 'com.google.code.findbugs:annotations:3.0.1'
compileOnly 'com.google.code.findbugs:jsr305:3.0.1'
}
Run Code Online (Sandbox Code Playgroud)
compileOnly是Maven称之为provided范围的Gradle风格.
SpotBugs更新(2018年):
FindBugs已被SpotBugs取代.因此,如果您已经在使用SpotBugs,则迁移指南建议您使用以下依赖项:
请依赖于spotbugs-annotations和net.jcip:jcip-annotations:1.0.
Maven的:
<dependency>
<groupId>net.jcip</groupId>
<artifactId>jcip-annotations</artifactId>
<version>1.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-annotations</artifactId>
<version>3.1.3</version>
<optional>true</optional>
</dependency>
Run Code Online (Sandbox Code Playgroud)
摇篮:
dependencies {
compileOnly 'net.jcip:jcip-annotations:1.0'
compileOnly 'com.github.spotbugs:spotbugs-annotations:3.1.3'
}
Run Code Online (Sandbox Code Playgroud)
如果您也使用过jsr305,那依赖性仍然与上面相同.