class SpotBugsTask extends DefaultTask
The Gradle task to run the SpotBugs analysis. All properties are optional.
Usage for Java project:
After you apply the SpotBugs Gradle plugin to project, SpotBugsTask is automatically
generated for each sourceSet. If you want to configure generated tasks, write build scripts like below:
spotbugsMain {
sourceDirs = sourceSets.main.allSource.srcDirs
classDirs = sourceSets.main.output
auxClassPaths = sourceSets.main.compileClasspath
ignoreFailures = false
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')
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.
| Fields inherited from class | Fields |
|---|---|
class DefaultTask |
TASK_NAME, TASK_DESCRIPTION, TASK_GROUP, TASK_TYPE, TASK_DEPENDS_ON, TASK_OVERWRITE, TASK_ACTION, TASK_CONSTRUCTOR_ARGS |
| Type | Name and description |
|---|---|
FileCollection |
auxClassPathsProperty to specify the aux class paths that contains the libraries to refer during analysis. |
FileCollection |
classDirsProperty to specify the directories that contains the target classes to analyze. |
FileCollection |
classes |
Property<Effort> |
effortProperty to adjust SpotBugs detectors. |
RegularFileProperty |
excludeFilterProperty to set the filter file to limit which bug should be reported. |
ListProperty<String> |
extraArgsProperty to specify the extra arguments for SpotBugs. |
Property<Boolean> |
ignoreFailures |
RegularFileProperty |
includeFilterProperty to set the filter file to limit which bug should be reported. |
ListProperty<String> |
jvmArgsProperty to specify the extra arguments for JVM process. |
Property<String> |
maxHeapSizeProperty to specify the max heap size ( -Xmx option) of JVM process.
|
ListProperty<String> |
omitVisitorsProperty to disable visitors (detectors) for analysis. |
ListProperty<String> |
onlyAnalyzeProperty to specify the target classes for analysis. |
Property<String> |
projectNameProperty to specify the name of project. |
Property<String> |
releaseProperty to specify the release identifier of project. |
Property<Confidence> |
reportLevelProperty to specify the level to report bugs. |
NamedDomainObjectContainer<SpotBugsReport> |
reportsProperty to specify which report you need. |
DirectoryProperty |
reportsDirProperty to set the directory to generate report files. |
Property<Boolean> |
showProgressProperty to enable progress reporting during the analysis. |
FileCollection |
sourceDirsProperty to specify the directories that contain the source of target classes to analyze. |
Property<Boolean> |
useAuxclasspathFileProperty to enable auxclasspathFromFile and prevent Argument List Too Long issues in java processes. |
ListProperty<String> |
visitorsProperty to enable visitors (detectors) for analysis. |
| Constructor and description |
|---|
SpotBugsTask
(ObjectFactory objects, org.gradle.workers.WorkerExecutor workerExecutor) |
| Type Params | Return Type | Name and description |
|---|---|---|
|
String |
getBaseName() |
|
FileCollection |
getClasses()Property to specify the target classes to analyse by SpotBugs. |
|
SpotBugsReport |
getFirstEnabledReport() |
|
boolean |
getIgnoreFailures() |
|
Set<File> |
getPluginJar() |
|
FileCollection |
getSpotbugsClasspath() |
|
void |
init(SpotBugsExtension extension)Set properties from extension right after the task creation. |
|
NamedDomainObjectContainer<? extends SpotBugsReport> |
reports(Closure<NamedDomainObjectContainer<? extends SpotBugsReport>> closure) |
|
NamedDomainObjectContainer<? extends SpotBugsReport> |
reports(Action<NamedDomainObjectContainer<? extends SpotBugsReport>> configureAction) |
|
void |
run() |
|
void |
setClasses(FileCollection fileCollection) |
|
void |
setEffort(String name) |
|
void |
setIgnoreFailures(Provider<Boolean> b) |
|
void |
setIgnoreFailures(boolean b) |
|
void |
setReportLevel(String name) |
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 specify the directories that contains the target classes to analyze. Default value is the output directory of the target sourceSet.
Property to adjust SpotBugs detectors. Default value is Effort.DEFAULT.
Property to set the filter file to limit which bug should be reported.
Note that this property will NOT limit which bug should be detected. To limit the target classes to analyze, use onlyAnalyze instead. To limit the visitors (detectors) to run, use visitors and omitVisitors instead.
See also SpotBugs Manual about Filter file.
Property to specify the extra arguments for SpotBugs. Default value is empty so SpotBugs will get no extra argument.
Property to set the filter file to limit which bug should be reported.
Note that this property will NOT limit which bug should be detected. To limit the target classes to analyze, use onlyAnalyze instead. To limit the visitors (detectors) to run, use visitors and omitVisitors instead.
See also SpotBugs Manual about Filter file.
Property to specify the extra arguments for JVM process. Default value is empty so JVM process will get no extra argument.
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 release identifier of project. Some reporting formats use this property. Default value is the version of your Gradle project.
Property to specify the level to report bugs. Default value is Confidence.DEFAULT.
Property to specify which report you need.
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.
Property to enable visitors (detectors) for analysis. Default is empty that means all visitors run analysis.
Property to specify the target classes to analyse by SpotBugs.
Default value is the all existing .class files in getClassDirs.
Set properties from extension right after the task creation. User may overwrite these properties by build script.
extension - the source extension to copy the properties.Groovy Documentation