Spot Bugs Task
This Gradle task runs the SpotBugs analysis. All properties are optional.
Usage for Java projects: After applying the SpotBugs Gradle plugin to your project, a SpotBugsTask is automatically generated for each sourceSet. If you need to configure the generated tasks, use the following build script as a guide:
spotbugsMain {
sourceSets = sourceSets.main.allSource.srcDirs
classDirs = sourceSets.main.output
auxClassPaths = sourceSets.main.compileClasspath
ignoreFailures = false
showStackTraces = true
showProgress = false
reportLevel = 'default'
effort = 'default'
visitors = [ 'FindSqlInjection', 'SwitchFallthrough' ]
omitVisitors = [ 'FindNonShortCircuit' ]
reportsDir = file("$buildDir/reports/spotbugs")
includeFilter = file('spotbugs-include.xml')
excludeFilter = file('spotbugs-exclude.xml')
baselineFile = file('spotbugs-baseline.xml')
onlyAnalyze = ['com.foobar.MyClass', 'com.foobar.mypkg.*']
projectName = name
release = version
extraArgs = [ '-nested:false' ]
jvmArgs = [ '-Duser.language=ja' ]
maxHeapSize = '512m'
See also SpotBugs Manual about configuration.
Properties
A file that lists class files and jar files to analyze.
Property to specify the aux class paths that contains the libraries to refer during analysis. Default value is the compile-scope dependencies of the target sourceSet.
Property to set the baseline file. This file is a Spotbugs result file, and all bugs reported in this file will not be reported in the final output.
Property to adjust SpotBugs detectors. Default value is Effort.DEFAULT.
Property to set the filter file to limit which bug should be reported.
Property to set the filter file to limit which bug should be reported.
Property to specify the max heap size (-Xmx
option) of JVM process. Default value is empty so the default configuration made by Gradle will be used.
Property to disable visitors (detectors) for analysis. Default is empty that means SpotBugs omits no visitor.
Property to specify the target classes for analysis. Default value is empty that means all classes are analyzed.
Property to specify the name of project. Some reporting formats use this property. Default value is "${project.name} (${task.name})"
.
Property to specify the level to report bugs. Default value is Confidence.DEFAULT.
Property defined to keep the backward compatibility with org.gradle.api.reporting.Reporting interface.
Property to set the directory to generate report files. Default is "$buildDir/reports/spotbugs/$taskName"}
.
Property to enable progress reporting during the analysis. Default value is false
.
Property to specify the directories that contain the source of target classes to analyze. Default value is the source directory of the target sourceSet.
Property to enable auxclasspathFromFile and prevent Argument List Too Long issues in java processes. Default value is false
.
Functions
Set properties from extension right after the task creation. User may overwrite these properties by build script.
Function defined to keep the backward compatibility with org.gradle.api.reporting.Reporting interface.