To install the latest version, add the following to the lib/bld/bld-wrapper.properties file:
bld.extension-pmd=com.uwyn.rife2:bld-spotbugsFor more information, please refer to the extensions documentation.
To install a binary distribution of SpotBugs please referer to its installation instruction.
To check for bugs in the main source code, add the following to your build file:
@BuildCommand(summary = "Runs SpotBugs on this project")
public void spotbugs() throws Exception {
new SpotBugsOperation()
.fromProject(this)
.home("/path/to/spotbugs/")
.execute();
}./bld compile spotbugsThe output will look something like:
[spotbugs] auxclasspath[build/main, lib/compile/foo-2.3.0.jar, ...]
[spotbugs] sourcepath[src/main/java, src/main/resources]
[spotbugs] analyze[build/main]
[spotbugs] Found 5 potential bugs in 2 classes
[spotbugs] file:///dev/example/src/main/java/com/example/Example.java:39
DCN_NULLPOINTER_EXCEPTION (https://spotbugs.readthedocs.io/en/latest/bugDescriptions.html#dcn-nullpointer-exception)
Method: hasSpace, Class: com.example.Example, Priority: 2, Rank: 17, Category: STYLE
--> NullPointerException caught
[spotbugs] file:///dev/example/src/main/java/com/example/Sample.java:27
EI_EXPOSE_REP (https://spotbugs.readthedocs.io/en/latest/bugDescriptions.html#ei-expose-rep)
Method: getList, Field: mutableList, Class: com.example.Sample, Priority: 2, Rank: 18, Category: MALICIOUS_CODE
--> May expose internal representation by returning reference to mutable object
...To also check the test source code, add the following to your build file:
@BuildCommand(summary = "Runs SpotBugs on this project")
public void spotbugs() throws Exception {
new SpotBugsOperation()
.fromProject(this, true) // check src/main and src/test
.spotBugsJar("/path/to/spotbugs/lib/spotbugs.jar")
.execute();
}./bld compile spotbugsPlease check the SpotBugsOperation documentation for all available configuration options.