从 findbugs-maven-plugin 到 spotbugs-maven-plugin 帮你找到代码中的bug
一、findbugs-maven-plugin
介绍:
Status: Since Findbugs is no longer maintained, please use Spotbugs which has a Maven plugin. It is located at here.
Please Note - This version is using Findbugs 3.0.1.
FindBugs looks for bugs in Java programs. It is based on the concept of bug patterns. A bug pattern is a code idiom that is often an error. Bug patterns arise for a variety of reasons:
- Difficult language features
- Misunderstood API methods
- Misunderstood invariants when code is modified during maintenance
- Garden variety mistakes: typos, use of the wrong boolean operator
FindBugs uses static analysis to inspect Java bytecode for occurrences of bug patterns. We have found that FindBugs finds real errors in most Java software. Because its analysis is sometimes imprecise, FindBugs can report false warnings, which are warnings that do not indicate real errors. In practice, the rate of false warnings reported by FindBugs is generally less than 50%.
FindBugs is free software, available under the terms of the Lesser GNU Public License. It is written in Java, and can be run with any virtual machine compatible with Java 7. It can analyze programs written for any version of Java. FindBugs was originally developed by Bill Pugh. It is maintained by Bill Pugh, David Hovemeyer, and a team of volunteers.
FindBugs uses BCEL to analyze Java bytecode. It uses dom4j for XML manipulation.
This introduction is an excerpt from the Facts Sheet at FindBugs home page.
To see more documentation about FindBugs' options, please see the FindBugs Manual.
Usage version3.0.6-SNAPSHOT/version The following examples describe the basic usage of the FindBugs plugin.
Generate FindBugs Report As Part of the Project Reports
To generate the FindBugs report as part of the Project Reports, add the FindBugs plugin in the <reporting> section of your pom.xml.
<project>
...
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.6-SNAPSHOT</version>
</plugin>
</plugins>
</reporting>
...
</project>
Then, execute the site plugin to generate the report.
mvn site
Generate FindBugs xdoc Report As Part of the Project Reports
To generate the FindBugs xdoc report as part of the Project Reports, add the FindBugs plugin in the <reporting> section of your pom.xml. This will be the same report as that of the Maven 1 FindBugs report. It is also the format used by Hudson. The output file will be written as findbugs.xml to either the default output directory of ${project.build.directory} or by that started in the <xmlOutputDirectory> option.
<project>
...
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.6-SNAPSHOT</version>
<configuration>
<xmlOutput>true</xmlOutput>
<!-- Optional directory to put findbugs xdoc xml report -->
<xmlOutputDirectory>target/site</xmlOutputDirectory>
</configuration>
</plugin>
</plugins>
</reporting>
...
</project>
Then, execute the site plugin to generate the report.
mvn site
Filter bugs to report
To filter the classes and methods which are analyzed or omitted from analysis you can use filters. The filters allow specifying by class and method which bug categories to include/exclude in/from the reports. The filter format specification also contains useful examples.
<project>
...
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.6-SNAPSHOT</version>
<configuration>
<excludeFilterFile>findbugs-exclude.xml</excludeFilterFile>
<includeFilterFile>findbugs-include.xml</includeFilterFile>
</configuration>
</plugin>
</plugins>
</reporting>
...
</project>
Then, execute the site plugin to generate the report.
mvn site
Specifying which bug filters to run
To filter the classes and methods which are analyzed or omitted from analysis you can use filters. The filters allow specifying by class and method which bug categories to include/exclude in/from the reports. The filter format specification also contains useful examples.
<project>
...
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.6-SNAPSHOT</version>
<configuration>
<excludeFilterFile>findbugs-exclude.xml</excludeFilterFile>
<includeFilterFile>findbugs-include.xml</includeFilterFile>
</configuration>
</plugin>
</plugins>
</reporting>
...
</project>
Then, execute the site plugin to generate the report.
mvn site
Specifying which bug detectors to run
The visitors option specifies a comma-separated list of bug detectors which should be run. The bug detectors are specified by their class names, without any package qualification. By default, all detectors which are not disabled are run.
<project>
...
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.6-SNAPSHOT</version>
<configuration>
<visitors>FindDeadLocalStores,UnreadFields</visitors>
</configuration>
</plugin>
</plugins>
</reporting>
...
</project>
Then, execute the site plugin to generate the report.
mvn site
Specifying which bug detectors to skip
The omitVisitors option is like the visitors attribute, except it specifies detectors which will not be run.
<project>
...
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.6-SNAPSHOT</version>
<configuration>
<omitVisitors>FindDeadLocalStores,UnreadFields</omitVisitors>
</configuration>
</plugin>
</plugins>
</reporting>
...
</project>
Then, execute the site plugin to generate the report.
mvn site
Specifying which classes to analyze
The onlyAnalyze option restricts analysis to the given comma-separated list of classes and packages.
<project>
...
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.6-SNAPSHOT</version>
<configuration>
<onlyAnalyze>org.codehaus.mojo.findbugs.*</onlyAnalyze>
</configuration>
</plugin>
</plugins>
</reporting>
...
</project>
Then, execute the site plugin to generate the report.
mvn site
Using Third party or your own detectors
The pluginList option specifies a comma-separated list of optional BugDetector Jar files to add.
<project>
...
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.6-SNAPSHOT</version>
<configuration>
<pluginList>myDetectors.jar, yourDetectors.jar</pluginList>
</configuration>
</plugin>
</plugins>
</reporting>
...
</project>
Then, execute the site plugin to generate the report.
mvn site
Using Detectors from a Repository
The plugins option defines a collection of PluginArtifact to work on. (PluginArtifact contains groupId, artifactId, version, type.)
<project>
...
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.6-SNAPSHOT</version>
<configuration>
<plugins>
<plugin>
<groupId>com.timgroup</groupId>
<artifactId>findbugs4jmock</artifactId>
<version>0.2</version>
</plugin>
</plugins>
</configuration>
</plugin>
</plugins>
</reporting>
...
</project>
Then, execute the site plugin to generate the report.
mvn site
Launch the Findbugs GUI
This will launch the FindBugs GUI configured for this project and will open the findbugsXml.xml file if present. It therefore assumes a pom.xml with the minimum as follows.
<project>
...
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.6-SNAPSHOT</version>
<configuration>
<!-- Optional directory to put findbugs xml report -->
</configuration>
</plugin>
</plugins>
</reporting>
...
</project>
Then, execute the findbugs plugin with the gui option.
mvn findbugs:gui
二、SpotBugs Maven Plugin
Introduction
SpotBugs is a program to find bugs in Java programs. It looks for instances of “bug patterns” — code instances that are likely to be errors.
This document describes version 4.0.3 of SpotBugs. We are very interested in getting your feedback on SpotBugs. Please visit the SpotBugs web page for the latest information on SpotBugs, contact information, and support resources such as information about the SpotBugs GitHub organization.
Requirements
To use SpotBugs, you need a runtime environment compatible with Java version 1.8 or later. SpotBugs is platform independent, and is known to run on GNU/Linux, Windows, and MacOS X platforms.
You should have at least 512 MB of memory to use SpotBugs. To analyze very large projects, more memory may be needed.
Supported Java version
SpotBugs is built by JDK8, and run on JRE8 and newer versions.
SpotBugs can scan bytecode (class files) generated by JDK8 and newer versions. However, support for Java 11 and newer is still experimental. Visit issue tracker to find known problems.
SpotBugs does not support bytecode (class files) generated by outdated JDK such as 10, 9, 7 and older versions.
- Introduction
- Requirements
- Installing
- Running SpotBugs
- Using the SpotBugs GUI
- Using the SpotBugs Eclipse plugin
- Using the SpotBugs Ant task
- Using the SpotBugs Maven Plugin
- Using the SpotBugs Gradle Plugin
- Filter file
- Analysis Properties
- Effort
- Implement SpotBugs plugin
- Use SpotBugs Plugin on SonarQube
- SpotBugs FAQ
- SpotBugs Links
- Bug descriptions
- Guide for migration from SpotBugs 3.1 to 4.0
- Guide for migration from FindBugs 3.0 to SpotBugs 3.1
- Annotations
- Docs »
- Using the SpotBugs Maven Plugin
- Edit on GitHub
Using the SpotBugs Maven Plugin
This chapter describes how to integrate SpotBugs into a Maven project.
Add spotbugs-maven-plugin to your pom.xml
Add <plugin> into your pom.xml like below:
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>4.0.0</version>
<dependencies>
<!-- overwrite dependency on spotbugs if you want to specify the version of spotbugs -->
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs</artifactId>
<version>4.0.3</version>
</dependency>
</dependencies>
</plugin>
Goals of spotbugs-maven-plugin
spotbugs goal
三、附加订阅

从 findbugs-maven-plugin 到 spotbugs-maven-plugin 帮你找到代码中的bug的更多相关文章
- FindBugs 入门——帮你减少代码中的bug数
FindBugs 入门 FindBugs 作用 开发人员在开发了一部分代码后,可以使用FindBugs进行代码缺陷的检查.提高代码的质量,同时也可以减少测试人员给你报的bug数. 代码缺陷分类 根据缺 ...
- CoreException: Could not get the value for parameter compilerId for plugin execution default-compile Maven项目pom文件报错,插件引用不到
CoreException: Could not get the value for parameter compilerId for plugin execution default-compile ...
- maven Error resolving version for plugin 'org.apache.maven.plugins:maven-eclipse-plugin' from the repositories 解决
报错:Error resolving version for plugin 'org.apache.maven.plugins:maven-eclipse-plugin' from the repos ...
- CoreException: Could not calculate build plan: Plugin org.apache.maven.plugins:maven-compiler-plugin:3.1 or one of its dependencies could not be resolved
CoreException: Could not calculate build plan: Plugin org.apache.maven.plugins:maven-compiler-plugin ...
- Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.5
Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of ...
- maven install 报错Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin
Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or one of ...
- Eclipse使用Maven,创建项目出现:Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resour
使用maven创建简单的项目时候经常会遇到 Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resource ...
- Maven的几个常用plugin
出自:https://www.cnblogs.com/zhangxh20/p/6298062.html maven-compiler-plugin 编译Java源码,一般只需设置编译的jdk版本 &l ...
- Maven系列(一)plugin
Maven系列(一)plugin maven-compiler-plugin 使用 mvn compile 命令,出现错误: 编码 GBK 的不可映射字符而不能编译.这是因为代码或注释中存在中文引起的 ...
- eclipse导入maven项目时报Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources
在用Eclipse IDE for Java EE Developers进行maven项目的开发时,报错Could not calculate build plan: Plugin org.apach ...
随机推荐
- win32 - DIB 与 DDB
设备相关位图(DDB): DDB不包含颜色值,因为每个设备可以具有自己的一组颜色,所以为一个设备创建的DDB可能无法在其他设备上很好地显示. DDB通常被称为兼容位图,并且它通常比DIB具有更好的GD ...
- pikachu php反序列化漏洞
原理 php中serialize(),unserialize()这两个函数. 序列化serialize() 序列化说通俗点就是把一个对象变成可以传输的字符串,比如下面是一个对象: class S{ p ...
- 具备有效期的sessionStorage存储
具备有效期的sessionStorage存储 类方式 // 具备有效期的sessionStorage存储-类方式. class SessionStorageWrapper { // 存储数据到sess ...
- vscode添加gitbash终端方法
1.打开vscode 2.点击文件,ctrl+, 3.搜索shell windows { ... // 添加如下代码 "terminal.integrated.profiles.window ...
- django中使用redis管道
管道(事务),要是都成功则成功,失败一个全部失败 原理:将数据操作放在内存中,只有成功后,才会一次性全部放入redis 记住,redis中的管道可以开启事务处理,但是并没有回滚这一说法!跟mysql中 ...
- ProtoBuffer-nanopb介绍
目录 一.需求 二.环境 三.相关概念 3.1 protocol buffer介绍 3.2 nanopb(支持C语言) 3.3 proto文件 四.proto基本语法 4.1 proto文件的定义 4 ...
- 07、Etcd 中Raft算法简介
本篇内容主要来源于自己学习的视频,如有侵权,请联系删除,谢谢. 思考: etcd是如何基于Raft来实现高可用.数据强-致性的? 1.什么是Raft算法 Raft 算法是现在分布式系统开发首选的共识算 ...
- Html飞机大战(十一): 飞机撞毁爆炸
好家伙,这篇写英雄撞机爆炸 我们先把子弹销毁弄上去 子弹穿过敌机,敌机爆炸后消失,子弹同样也应该销毁,(当然后续会考虑穿甲弹) 然后我们还要把主角碰撞爆炸检测也加上去 因为他们共用一个思路 ...
- 用 NetworkX + Gephi + Nebula Graph 分析<权力的游戏>人物关系(上篇)
我们都知道<权利的游戏>在全世界都很多忠实的粉丝,除去你永远不知道剧情下一秒谁会挂这种意外"惊喜",当中复杂交错的人物关系也是它火爆的原因之一,而本文介绍如何通过 Ne ...
- 在Avalonia项目中使用MediatR和MS.DI库实现事件驱动通信
大家好,我是沙漠尽头的狼! AvaloniaUI是一个强大的跨平台.NET客户端开发框架,让开发者能够针对Windows.Linux.macOS.Android和iOS等多个平台构建应用程序.在构建复 ...