SpotBugsTask

@CacheableTask
abstract class SpotBugsTask : DefaultTask, VerificationTask

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' ]
chooseVisitors = [ '-FindNonShortCircuit', '+TestASM' ]
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.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
open var actions: List<Action<in Task?>?>?
Link copied to clipboard
@get:OutputFile
abstract val analyseClassFile: RegularFileProperty

A file that lists class files and jar files to analyze.

Link copied to clipboard
open val ant: AntBuilder?
Link copied to clipboard
@get:Internal
open val asDynamicObject: DynamicObject?
Link copied to clipboard
@get:Internal
abstract val auxclasspathFile: RegularFileProperty
Link copied to clipboard
@get:Classpath
abstract val auxClassPaths: ConfigurableFileCollection

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.

Link copied to clipboard
@get:Optional
@get:InputFile
@get:PathSensitive(value = PathSensitivity.RELATIVE)
abstract val baselineFile: RegularFileProperty

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.

Link copied to clipboard
@get:Input
abstract val chooseVisitors: ListProperty<String>

Property to selectively enable/disable visitors (detectors) for analysis. Default is empty that means SpotBugs those visitors run which are enabled by default. This is a list with "+" or "-" before each detectors' name indicating enabling or disabling.

Link copied to clipboard
@get:Internal
abstract val classDirs: ConfigurableFileCollection

Property to specify the directories that contains the target classes to analyze. Default value is the output directory of the target sourceSet.

Link copied to clipboard
@get:InputFiles
@get:PathSensitive(value = PathSensitivity.RELATIVE)
@get:SkipWhenEmpty
var classes: FileCollection?

Property to specify the target classes to analyze by SpotBugs. Default value is the all existing .class files in getClassDirs.

Link copied to clipboard
@get:Internal
open override val convention: Convention?
Link copied to clipboard
open val dependsOn: Set<Any?>?
Link copied to clipboard
open var description: String?
Link copied to clipboard
open val destroyables: TaskDestroyables?
Link copied to clipboard
open var didWork: Boolean
Link copied to clipboard
@get:Input
@get:Optional
abstract val effort: Property<Effort>

Property to adjust SpotBugs detectors. Default value is Effort.DEFAULT.

Link copied to clipboard
open var enabled: Boolean
Link copied to clipboard
@get:Optional
@get:InputFile
@get:PathSensitive(value = PathSensitivity.RELATIVE)
abstract val excludeFilter: RegularFileProperty

Property to set the filter file to limit which bug should be reported.

Link copied to clipboard
@get:Inject
abstract val execOps: ExecOperations
Link copied to clipboard
open val extensions: ExtensionContainer?
Link copied to clipboard
@get:Optional
@get:Input
abstract val extraArgs: ListProperty<String>

Property to specify the extra arguments for SpotBugs. Default value is empty so SpotBugs will get no extra argument.

Link copied to clipboard
open val finalizedBy: TaskDependency?
Link copied to clipboard
open var group: String?
Link copied to clipboard
open val identityPath: Path?
Link copied to clipboard
@get:Input
open override var ignoreFailures: Boolean
Link copied to clipboard
Link copied to clipboard
@get:Optional
@get:InputFile
@get:PathSensitive(value = PathSensitivity.RELATIVE)
abstract val includeFilter: RegularFileProperty

Property to set the filter file to limit which bug should be reported.

Link copied to clipboard
open val inputs: TaskInputsInternal?
Link copied to clipboard
@get:Internal
open var isEnabled: Boolean
Link copied to clipboard
Link copied to clipboard
@get:Optional
@get:Input
abstract val jvmArgs: ListProperty<String>

Property to specify the extra arguments for JVM process. Default value is empty so JVM process will get no extra argument.

Link copied to clipboard
@get:Optional
abstract val launcher: Property<JavaLauncher>
Link copied to clipboard
@get:Internal
open val lifecycleDependencies: TaskDependencyInternal?
Link copied to clipboard
open val localState: TaskLocalState?
Link copied to clipboard
open val logger: Logger?
Link copied to clipboard
open val logging: LoggingManager?
Link copied to clipboard
@get:Optional
@get:Input
abstract val maxHeapSize: Property<String>

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.

Link copied to clipboard
open val mustRunAfter: TaskDependency?
Link copied to clipboard
open val name: String?
Link copied to clipboard
@get:Input
abstract val omitVisitors: ListProperty<String>

Property to disable visitors (detectors) for analysis. Default is empty that means SpotBugs omits no visitor.

Link copied to clipboard
@get:Input
abstract val onlyAnalyze: ListProperty<String>

Property to specify the target classes for analysis. Default value is empty that means all classes are analyzed.

Link copied to clipboard
open val onlyIf: Spec<in TaskInternal?>?
Link copied to clipboard
open val outputs: TaskOutputsInternal?
Link copied to clipboard
open val path: String?
Link copied to clipboard
@get:Classpath
abstract val pluginJarFiles: ConfigurableFileCollection
Link copied to clipboard
open val project: Project?
Link copied to clipboard
@get:Internal
abstract val projectName: Property<String>

Property to specify the name of project. Some reporting formats use this property. Default value is "${project.name} (${task.name})".

Link copied to clipboard
Link copied to clipboard
@get:Input
abstract val release: Property<String>

Property to specify the release identifier of project. Some reporting formats use this property. Default value is the version of your Gradle project.

Link copied to clipboard
@get:Input
@get:Optional
abstract val reportLevel: Property<Confidence>

Property to specify the level to report bugs. Default value is Confidence.DEFAULT.

Link copied to clipboard
@get:Internal
val reports: NamedDomainObjectContainer<SpotBugsReport>

Property defined to keep the backward compatibility with org.gradle.api.reporting.Reporting interface.

Link copied to clipboard
@get:Internal(value = "Refer the destination of each report instead.")
abstract val reportsDir: DirectoryProperty

Property to set the directory to generate report files. Default is "$buildDir/reports/spotbugs/$taskName"}.

Link copied to clipboard
open val requiredServices: TaskRequiredServices?
Link copied to clipboard
open val sharedResources: List<ResourceLock?>?
Link copied to clipboard
open val shouldRunAfter: TaskDependency?
Link copied to clipboard
@get:Optional
@get:Input
abstract val showProgress: Property<Boolean>

Property to enable progress reporting during the analysis. Default value is false.

Link copied to clipboard
@get:Input
abstract val showStackTraces: Property<Boolean>
Link copied to clipboard
@get:InputFiles
@get:PathSensitive(value = PathSensitivity.RELATIVE)
abstract val sourceDirs: ConfigurableFileCollection

Property to specify the directories that contain the source of target classes to analyze. Default value is the source directory of the target sourceSet.

Link copied to clipboard
@get:Classpath
abstract val spotbugsClasspath: ConfigurableFileCollection
Link copied to clipboard
open val standardOutputCapture: StandardOutputCapture?
Link copied to clipboard
open val state: TaskStateInternal?
Link copied to clipboard
open val taskActions: List<InputChangesAwareTaskAction?>?
Link copied to clipboard
open val taskDependencies: TaskDependencyInternal?
Link copied to clipboard
open val taskIdentity: TaskIdentity<*>?
Link copied to clipboard
open val temporaryDir: File?
Link copied to clipboard
open val temporaryDirFactory: Factory<File?>?
Link copied to clipboard
open val timeout: Property<Duration?>?
Link copied to clipboard
@get:Input
@get:Optional
abstract val useAuxclasspathFile: Property<Boolean>

Property to enable auxclasspathFromFile and prevent Argument List Too Long issues in java processes. Default value is false.

Link copied to clipboard
@get:Input
abstract val visitors: ListProperty<String>

Property to enable visitors (detectors) for analysis. Default is empty that means all visitors run analysis.

Link copied to clipboard
@get:Inject
abstract val workerExecutor: WorkerExecutor

Functions

Link copied to clipboard
open fun acceptServiceReferences(serviceReferences: Set<ServiceReferenceSpec?>?)
Link copied to clipboard
open fun appendParallelSafeAction(action: Action<in Task?>?)
Link copied to clipboard
open operator fun compareTo(otherTask: Task?): Int
Link copied to clipboard
open fun configure(closure: Closure<*>?): Task?
Link copied to clipboard
open fun dependsOn(vararg paths: Any?): Task?
Link copied to clipboard
open fun doFirst(action: Closure<*>?): Task?
open fun doFirst(action: Action<in Task?>?): Task?
open fun doFirst(actionName: String?, action: Action<in Task?>?): Task?
Link copied to clipboard
open fun doLast(action: Closure<*>?): Task?
open fun doLast(action: Action<in Task?>?): Task?
open fun doLast(actionName: String?, action: Action<in Task?>?): Task?
Link copied to clipboard
open fun doNotTrackState(reasonNotToTrackState: String?)
Link copied to clipboard
open fun finalizedBy(vararg paths: Any?): Task?
Link copied to clipboard
@Internal
fun getBaseName(): String
Link copied to clipboard
@Internal
open fun getConvention(): Convention?
Link copied to clipboard
@Input
open override fun getIgnoreFailures(): Boolean
Link copied to clipboard
open fun hasProperty(propertyName: String?): Boolean
Link copied to clipboard
Link copied to clipboard
fun init(extension: SpotBugsExtension, enableWorkerApi: Boolean)

Set properties from extension right after the task creation. User may overwrite these properties by build script.

Link copied to clipboard
open fun mustRunAfter(vararg paths: Any?): Task?
Link copied to clipboard
open fun onlyIf(onlyIfClosure: Closure<*>?)
open fun onlyIf(spec: Spec<in Task?>?)
open fun onlyIf(onlyIfReason: String?, spec: Spec<in Task?>?)
Link copied to clipboard
open fun prependParallelSafeAction(action: Action<in Task?>?)
Link copied to clipboard
open fun property(propertyName: String?): Any?
Link copied to clipboard
fun reports(configureAction: Action<NamedDomainObjectContainer<SpotBugsReport>>): NamedDomainObjectContainer<SpotBugsReport>

Function defined to keep the backward compatibility with org.gradle.api.reporting.Reporting interface.

Link copied to clipboard
fun run()
Link copied to clipboard
open fun setDependsOn(dependsOn: Iterable<*>?)
Link copied to clipboard
open fun setFinalizedBy(finalizedByTasks: Iterable<*>?)
Link copied to clipboard
open override fun setIgnoreFailures(ignoreFailures: Boolean)
Link copied to clipboard
open fun setMustRunAfter(mustRunAfterTasks: Iterable<*>?)
Link copied to clipboard
open fun setOnlyIf(onlyIfClosure: Closure<*>?)
open fun setOnlyIf(spec: Spec<in Task?>?)
open fun setOnlyIf(onlyIfReason: String?, spec: Spec<in Task?>?)
Link copied to clipboard
open fun setProperty(name: String?, value: Any?)
Link copied to clipboard
open fun setShouldRunAfter(shouldRunAfterTasks: Iterable<*>?)
Link copied to clipboard
open fun shouldRunAfter(vararg paths: Any?): TaskDependency?
Link copied to clipboard
open fun usesService(service: Provider<out BuildService<*>?>?)