@CacheableTask abstract class SpotBugsTask extends DefaultTask implements VerificationTask
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
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.
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 |
auxClassPaths Property to specify the aux class paths that contains the libraries to refer during analysis. |
RegularFileProperty |
baselineFile Property to set the baseline file. |
FileCollection |
classDirs Property to specify the directories that contains the target classes to analyze. |
FileCollection |
classes |
Property<Effort> |
effort Property to adjust SpotBugs detectors. |
RegularFileProperty |
excludeFilter Property to set the filter file to limit which bug should be reported. |
ListProperty<String> |
extraArgs Property to specify the extra arguments for SpotBugs. |
Property<Boolean> |
ignoreFailures |
RegularFileProperty |
includeFilter Property to set the filter file to limit which bug should be reported. |
ListProperty<String> |
jvmArgs Property to specify the extra arguments for JVM process. |
Property<String> |
maxHeapSize Property to specify the max heap size ( -Xmx option) of JVM process.
|
ListProperty<String> |
omitVisitors Property to disable visitors (detectors) for analysis. |
ListProperty<String> |
onlyAnalyze Property to specify the target classes for analysis. |
Property<String> |
projectName Property to specify the name of project. |
Property<String> |
release Property to specify the release identifier of project. |
Property<com.github.spotbugs.snom.Confidence> |
reportLevel Property to specify the level to report bugs. |
NamedDomainObjectContainer<SpotBugsReport> |
reports Property to specify which report you need. |
DirectoryProperty |
reportsDir Property to set the directory to generate report files. |
Property<Boolean> |
showProgress Property to enable progress reporting during the analysis. |
Property<Boolean> |
showStackTraces |
FileCollection |
sourceDirs Property to specify the directories that contain the source of target classes to analyze. |
Property<Boolean> |
useAuxclasspathFile Property to enable auxclasspathFromFile and prevent Argument List Too Long issues in java processes. |
ListProperty<String> |
visitors Property to enable visitors (detectors) for analysis. |
Constructor and description |
---|
SpotBugsTask
(ObjectFactory objects, org.gradle.workers.WorkerExecutor workerExecutor) |
Type Params | Return Type | Name and description |
---|---|---|
|
abstract RegularFileProperty |
getAnalyseClassFile() A file that lists class files and jar files to analyse. |
|
String |
getBaseName() |
|
FileCollection |
getClasses() Property to specify the target classes to analyse by SpotBugs. |
|
Set<SpotBugsReport> |
getEnabledReports() |
|
SpotBugsReport |
getFirstEnabledReport() |
|
boolean |
getIgnoreFailures() |
|
abstract Property<JavaLauncher> |
getLauncher() |
|
Set<File> |
getPluginJar() |
|
boolean |
getShowStackTraces() |
|
FileCollection |
getSpotbugsClasspath() |
|
void |
init(SpotBugsExtension extension, boolean enableWorkerApi, boolean enableHybridWorker) Set properties from extension right after the task creation. |
|
boolean |
isSupportingMultipleReports() The multiple reports feature is available from SpotBugs 4.5.0 |
|
final NamedDomainObjectContainer<? extends SpotBugsReport> |
reports(Closure<NamedDomainObjectContainer<? extends SpotBugsReport>> closure) |
|
final 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) |
|
void |
setShowStackTraces(Provider<Boolean> b) |
|
void |
setShowStackTraces(boolean b) |
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 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})"}.
Note that this property, if treated as a task input, can break cacheability.
As such, it has been marked Internal to exclude it from task up-to-date and
cacheability checks.
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 com.github.spotbugs.snom.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
.
A file that lists class files and jar files to analyse.
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.The multiple reports feature is available from SpotBugs 4.5.0
Groovy Documentation