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' ]
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
@get:OutputFile
abstract val analyseClassFile: RegularFileProperty

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

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: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:Input
@get:Optional
abstract val effort: Property<Effort>

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

Link copied to clipboard
@get:Internal
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
@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
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
@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: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
@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
@get:Classpath
abstract val pluginJarFiles: ConfigurableFileCollection
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
@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
@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
val state: TaskStateInternal
Link copied to clipboard
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 override fun acceptServiceReferences(serviceReferences: MutableSet<ServiceReferenceSpec>)
Link copied to clipboard
open override fun appendParallelSafeAction(action: Action<in Task>)
Link copied to clipboard
open operator override fun compareTo(other: Task): Int
Link copied to clipboard
open override fun configure(closure: Closure<Any>): Task
Link copied to clipboard
open override fun dependsOn(vararg paths: Any): Task
Link copied to clipboard
open override fun doFirst(action: Closure<Any>): Task
open override fun doFirst(action: Action<in Task>): Task
open override fun doFirst(actionName: String, action: Action<in Task>): Task
Link copied to clipboard
open override fun doLast(action: Closure<Any>): Task
open override fun doLast(action: Action<in Task>): Task
open override fun doLast(actionName: String, action: Action<in Task>): Task
Link copied to clipboard
open override fun doNotTrackState(reasonNotToTrackState: String)
Link copied to clipboard
open override fun finalizedBy(vararg paths: Any): Task
Link copied to clipboard
open override fun getActions(): MutableList<Action<in Task>>
Link copied to clipboard
open override fun getAnt(): AntBuilder
Link copied to clipboard
@Internal
open override fun getAsDynamicObject(): DynamicObject
Link copied to clipboard
@Internal
fun getBaseName(): String
Link copied to clipboard
@Internal
open override fun getConvention(): Convention
Link copied to clipboard
open override fun getDependsOn(): MutableSet<Any>
Link copied to clipboard
open override fun getDescription(): String?
Link copied to clipboard
open override fun getDestroyables(): TaskDestroyables
Link copied to clipboard
open override fun getDidWork(): Boolean
Link copied to clipboard
open override fun getExtensions(): ExtensionContainer
Link copied to clipboard
open override fun getFinalizedBy(): TaskDependency
Link copied to clipboard
open override fun getGroup(): String?
Link copied to clipboard
open override fun getIdentityPath(): Path
Link copied to clipboard
@Input
open override fun getIgnoreFailures(): Boolean
Link copied to clipboard
open override fun getInputs(): TaskInputsInternal
Link copied to clipboard
@Internal
open override fun getLifecycleDependencies(): TaskDependencyInternal
Link copied to clipboard
open override fun getLocalState(): TaskLocalState
Link copied to clipboard
open override fun getLogger(): Logger
Link copied to clipboard
open override fun getLogging(): LoggingManager
Link copied to clipboard
open override fun getMustRunAfter(): TaskDependency
Link copied to clipboard
open override fun getName(): String
Link copied to clipboard
open override fun getOnlyIf(): Spec<in TaskInternal>
Link copied to clipboard
open override fun getOutputs(): TaskOutputsInternal
Link copied to clipboard
open override fun getPath(): String
Link copied to clipboard
open override fun getProject(): Project
Link copied to clipboard
Link copied to clipboard
open override fun getRequiredServices(): TaskRequiredServices
Link copied to clipboard
open override fun getSharedResources(): MutableList<ResourceLock>
Link copied to clipboard
open override fun getShouldRunAfter(): TaskDependency
Link copied to clipboard
open override fun getStandardOutputCapture(): StandardOutputCapture
Link copied to clipboard
open override fun getTaskActions(): MutableList<InputChangesAwareTaskAction>
Link copied to clipboard
open override fun getTaskDependencies(): TaskDependencyInternal
Link copied to clipboard
open override fun getTaskIdentity(): TaskIdentity<*>
Link copied to clipboard
open override fun getTemporaryDir(): File
Link copied to clipboard
open override fun getTemporaryDirFactory(): Factory<File>
Link copied to clipboard
open override fun hasProperty(propertyName: String): Boolean
Link copied to clipboard
open override fun hasTaskActions(): Boolean
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
Link copied to clipboard
open override fun mustRunAfter(vararg paths: Any): Task
Link copied to clipboard
open override fun notCompatibleWithConfigurationCache(reason: String)
Link copied to clipboard
open override fun onlyIf(onlyIfClosure: Closure<Any>)
open override fun onlyIf(spec: Spec<in Task>)
open override fun onlyIf(onlyIfReason: String, spec: Spec<in Task>)
Link copied to clipboard
open override fun prependParallelSafeAction(action: Action<in Task>)
Link copied to clipboard
open override 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 override fun setActions(replacements: MutableList<Action<in Task>>)
Link copied to clipboard
open override fun setDependsOn(dependsOn: MutableIterable<*>)
Link copied to clipboard
open override fun setDescription(description: String?)
Link copied to clipboard
open override fun setDidWork(didWork: Boolean)
Link copied to clipboard
open override fun setFinalizedBy(finalizedByTasks: MutableIterable<*>)
Link copied to clipboard
open override fun setGroup(group: String?)
Link copied to clipboard
open override fun setIgnoreFailures(ignoreFailures: Boolean)
Link copied to clipboard
open override fun setMustRunAfter(mustRunAfterTasks: MutableIterable<*>)
Link copied to clipboard
open override fun setOnlyIf(onlyIfClosure: Closure<Any>)
open override fun setOnlyIf(spec: Spec<in Task>)
open override fun setOnlyIf(onlyIfReason: String, spec: Spec<in Task>)
Link copied to clipboard
open override fun setProperty(name: String, value: Any)
Link copied to clipboard
open override fun setShouldRunAfter(shouldRunAfterTasks: MutableIterable<*>)
Link copied to clipboard
open override fun shouldRunAfter(vararg paths: Any): TaskDependency
Link copied to clipboard
open override fun usesService(service: Provider<out BuildService<*>>)