Class DefaultTask
- All Implemented Interfaces:
Comparable<Task>
,org.gradle.api.internal.DynamicObjectAware
,org.gradle.api.internal.TaskInternal
,Named
,ExtensionAware
,Task
,Configurable<Task>
- Direct Known Subclasses:
AbstractConfigurationReportTask
,AbstractLinkTask
,AbstractNativeCompileTask
,AbstractPublishToMaven
,Assemble
,BuildEnvironmentReportTask
,ComponentReport
,org.gradle.api.internal.ConventionTask
,CreateStaticLibrary
,DependencyInsightReportTask
,DependentComponentsReport
,ExtractSymbols
,GenerateBuildDashboard
,GenerateCUnitLauncher
,GenerateIvyDescriptor
,GenerateMavenPom
,GenerateModuleMetadata
,GeneratePluginDescriptors
,GenerateSwiftPackageManagerManifest
,InitBuild
,InstallExecutable
,InstallXCTestBundle
,JacocoBase
,ModelReport
,PluginUnderTestMetadata
,PrefixHeaderFileGenerateTask
,PublishToIvyRepository
,Sign
,StripSymbols
,SwiftCompile
,TestReport
,UnexportMainSymbol
,UpdateDaemonJvm
,ValidatePlugins
,WindowsResourceCompile
,Wrapper
,WriteProperties
DefaultTask
is the standard Task
implementation. You can extend this to implement your own task types.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.gradle.api.Task
Task.Namer
-
Field Summary
Fields inherited from interface org.gradle.api.Task
TASK_ACTION, TASK_CONSTRUCTOR_ARGS, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
Applies the statements of the closure against this task object.Adds the given dependencies to this task.Adds the given closure to the beginning of this task's action list.Adds the givenAction
to the beginning of this task's action list.Adds the givenAction
to the beginning of this task's action list.Adds the given closure to the end of this task's action list.Adds the givenAction
to the end of this task's action list.Adds the givenAction
to the end of this task's action list.finalizedBy
(Object... paths) Adds the given finalizer tasks for this task.Returns the sequence ofAction
objects which will be executed by this task, in the order of execution.getAnt()
Returns theAntBuilder
for this task.Returns the dependencies of this task.Returns the description of this task.Returns the destroyables of this task.boolean
Checks if the task actually did any work.boolean
Returns if this task is enabled or not.The container of extensions.Returns tasks that finalize this task.getGroup()
Returns the task group which this task belongs to.org.gradle.api.internal.TaskInputsInternal
Returns the inputs of this task.Returns the local state of this task.Returns the logger for this task.Returns theLoggingManager
which can be used to receive logging and to control the standard output/error capture for this task.Returns tasks that this task must run after.getName()
Returns the name of this task.org.gradle.api.internal.TaskOutputsInternal
Returns the outputs of this task.getPath()
Returns the path of the task, which is a fully qualified name for the task.Returns theProject
which this task belongs to.Returns tasks that this task should run after.org.gradle.api.internal.tasks.TaskStateInternal
getState()
Returns the execution state of this task.org.gradle.api.internal.tasks.TaskDependencyInternal
Returns aTaskDependency
which contains all the tasks that this task depends on.Returns a directory which this task can use to write temporary files to.The timeout of this task.boolean
hasProperty
(String propertyName) Determines if this task has the given property.mustRunAfter
(Object... paths) Specifies that this task must run after all of the supplied tasks.void
Execute the task only if the given closure returns true.void
Execute the task only if the given spec is satisfied.void
Execute the task only if the given spec is satisfied.Returns the value of the given property of this task.void
setActions
(List<Action<? super Task>> replacements) Sets the sequence ofAction
objects which will be executed by this task.void
setDependsOn
(Iterable<?> dependsOn) Sets the dependencies of this task.void
setDescription
(String description) Sets a description for this task.void
setDidWork
(boolean didWork) Sets whether the task actually did any work.void
setEnabled
(boolean enabled) Set the enabled state of a task.void
setFinalizedBy
(Iterable<?> finalizedByTasks) Specifies the set of finalizer tasks for this task.void
Sets the task group which this task belongs to.void
setMustRunAfter
(Iterable<?> mustRunAfterTasks) Specifies the set of tasks that this task must run after.void
Execute the task only if the given closure returns true.void
Execute the task only if the given spec is satisfied.void
Execute the task only if the given spec is satisfied.void
setProperty
(String name, Object value) Sets a property of this task.void
setShouldRunAfter
(Iterable<?> shouldRunAfterTasks) Specifies the set of tasks that this task should run after.shouldRunAfter
(Object... paths) Specifies that this task should run after all of the supplied tasks.void
usesService
(Provider<? extends BuildService<?>> service) Registers aBuildService
that is used by this task soits constraint on parallel execution
can be honored.Methods inherited from class org.gradle.api.internal.AbstractTask
acceptServiceReferences, appendParallelSafeAction, doNotTrackState, getAsDynamicObject, getConvention, getIdentityPath, getImpliesSubProjects, getLifecycleDependencies, getOnlyIf, getReasonNotToTrackState, getReasonTaskIsIncompatibleWithConfigurationCache, getRequiredServices, getServices, getSharedResources, getStandardOutputCapture, getTaskActions, getTaskIdentity, getTemporaryDirFactory, hasTaskActions, injectIntoNewInstance, isCompatibleWithConfigurationCache, isEnabled, isHasCustomActions, notCompatibleWithConfigurationCache, prependParallelSafeAction, setImpliesSubProjects
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.gradle.api.Task
doNotTrackState, getConvention, notCompatibleWithConfigurationCache
-
Constructor Details
-
DefaultTask
public DefaultTask()
-
-
Method Details
-
getAnt
Description copied from interface:Task
Returns the
AntBuilder
for this task. You can use this in your build file to execute ant tasks. -
getProject
Description copied from interface:Task
Returns the
Project
which this task belongs to.Calling this method from a task action is not supported when configuration caching is enabled.
- Specified by:
getProject
in interfaceTask
- Overrides:
getProject
in classorg.gradle.api.internal.AbstractTask
- Returns:
- The project this task belongs to. Never returns null.
-
getName
Description copied from interface:Task
Returns the name of this task. The name uniquely identifies the task within its
Project
. -
getActions
Description copied from interface:Task
Returns the sequence of
Action
objects which will be executed by this task, in the order of execution.- Specified by:
getActions
in interfaceTask
- Overrides:
getActions
in classorg.gradle.api.internal.AbstractTask
- Returns:
- The task actions in the order they are executed. Returns an empty list if this task has no actions.
-
setActions
Description copied from interface:Task
Sets the sequence of
Action
objects which will be executed by this task.- Specified by:
setActions
in interfaceTask
- Overrides:
setActions
in classorg.gradle.api.internal.AbstractTask
- Parameters:
replacements
- The actions.
-
getDependsOn
Description copied from interface:Task
Returns the dependencies of this task.
- Specified by:
getDependsOn
in interfaceTask
- Overrides:
getDependsOn
in classorg.gradle.api.internal.AbstractTask
- Returns:
- The dependencies of this task. Returns an empty set if this task has no dependencies.
-
setDependsOn
Description copied from interface:Task
Sets the dependencies of this task. See here for a description of the types of objects which can be used as task dependencies.
- Specified by:
setDependsOn
in interfaceTask
- Overrides:
setDependsOn
in classorg.gradle.api.internal.AbstractTask
- Parameters:
dependsOn
- The set of task paths.
-
onlyIf
Description copied from interface:Task
Execute the task only if the given spec is satisfied. The spec will be evaluated at task execution time, not during configuration. If the Spec is not satisfied, the task will be skipped.
You may add multiple such predicates. The task is skipped if any of the predicates return false.
Typical usage (from Java):
myTask.onlyIf(new Spec<Task>() { boolean isSatisfiedBy(Task task) { return isProductionEnvironment(); } });
-
onlyIf
Description copied from interface:Task
Execute the task only if the given spec is satisfied. The spec will be evaluated at task execution time, not during configuration. If the Spec is not satisfied, the task will be skipped.
You may add multiple such predicates. The task is skipped if any of the predicates return false.
Typical usage (from Java):
myTask.onlyIf("run only in production environment", new Spec<Task>() { boolean isSatisfiedBy(Task task) { return isProductionEnvironment(); } });
-
setOnlyIf
Description copied from interface:Task
Execute the task only if the given spec is satisfied. The spec will be evaluated at task execution time, not during configuration. If the Spec is not satisfied, the task will be skipped.
The given predicate replaces all such predicates for this task.
-
setOnlyIf
Description copied from interface:Task
Execute the task only if the given spec is satisfied. The spec will be evaluated at task execution time, not during configuration. If the Spec is not satisfied, the task will be skipped.
The given predicate replaces all such predicates for this task.
-
getDidWork
public boolean getDidWork()Description copied from interface:Task
Checks if the task actually did any work. Even if a Task executes, it may determine that it has nothing to do. For example, a compilation task may determine that source files have not changed since the last time a the task was run.
- Specified by:
getDidWork
in interfaceTask
- Overrides:
getDidWork
in classorg.gradle.api.internal.AbstractTask
- Returns:
- true if this task did any work
-
setDidWork
public void setDidWork(boolean didWork) Description copied from interface:Task
Sets whether the task actually did any work. Most built-in tasks will set this automatically, but it may be useful to manually indicate this for custom user tasks.- Specified by:
setDidWork
in interfaceTask
- Overrides:
setDidWork
in classorg.gradle.api.internal.AbstractTask
- Parameters:
didWork
- indicates if the task did any work
-
getEnabled
public boolean getEnabled()Description copied from interface:Task
Returns if this task is enabled or not.
- Specified by:
getEnabled
in interfaceTask
- Overrides:
getEnabled
in classorg.gradle.api.internal.AbstractTask
- See Also:
-
setEnabled
public void setEnabled(boolean enabled) Description copied from interface:Task
Set the enabled state of a task. If a task is disabled none of the its actions are executed. Note that disabling a task does not prevent the execution of the tasks which this task depends on.
- Specified by:
setEnabled
in interfaceTask
- Overrides:
setEnabled
in classorg.gradle.api.internal.AbstractTask
- Parameters:
enabled
- The enabled state of this task (true or false)
-
getPath
Description copied from interface:Task
Returns the path of the task, which is a fully qualified name for the task. The path of a task is the path of its
Project
plus the name of the task, separated by:
. -
dependsOn
Description copied from interface:Task
Adds the given dependencies to this task. See here for a description of the types of objects which can be used as task dependencies.
-
doFirst
Description copied from interface:Task
Adds the given
Action
to the beginning of this task's action list. -
doFirst
Description copied from interface:Task
Adds the given
Action
to the beginning of this task's action list. -
doLast
Description copied from interface:Task
Adds the given
Action
to the end of this task's action list. -
doLast
Description copied from interface:Task
Adds the given
Action
to the end of this task's action list. -
compareTo
- Specified by:
compareTo
in interfaceComparable<Task>
- Overrides:
compareTo
in classorg.gradle.api.internal.AbstractTask
-
getLogger
Description copied from interface:Task
Returns the logger for this task. You can use this in your build file to write log messages.
-
property
Description copied from interface:Task
Returns the value of the given property of this task. This method locates a property as follows:
- If this task object has a property with the given name, return the value of the property.
- If this task has an extension with the given name, return the extension.
- If this task's convention object has a property with the given name, return the value of the property.
- If this task has an extra property with the given name, return the value of the property.
- If not found, throw
MissingPropertyException
- Specified by:
property
in interfaceTask
- Overrides:
property
in classorg.gradle.api.internal.AbstractTask
- Parameters:
propertyName
- The name of the property.- Returns:
- The value of the property, possibly null.
- Throws:
MissingPropertyException
- When the given property is unknown.
-
hasProperty
Description copied from interface:Task
Determines if this task has the given property. See here for details of the properties which are available for a task.
- Specified by:
hasProperty
in interfaceTask
- Overrides:
hasProperty
in classorg.gradle.api.internal.AbstractTask
- Parameters:
propertyName
- The name of the property to locate.- Returns:
- True if this project has the given property, false otherwise.
-
setProperty
Description copied from interface:Task
Sets a property of this task. This method searches for a property with the given name in the following locations, and sets the property on the first location where it finds the property.
- The task object itself. For example, the
enabled
project property. - The task's convention object.
- The task's extra properties.
MissingPropertyException
is thrown.- Specified by:
setProperty
in interfaceTask
- Overrides:
setProperty
in classorg.gradle.api.internal.AbstractTask
- Parameters:
name
- The name of the propertyvalue
- The value of the property
- The task object itself. For example, the
-
getDescription
Description copied from interface:Task
Returns the description of this task.- Specified by:
getDescription
in interfaceTask
- Overrides:
getDescription
in classorg.gradle.api.internal.AbstractTask
- Returns:
- the description. May return null.
-
setDescription
Description copied from interface:Task
Sets a description for this task. This should describe what the task does to the user of the build. The description will be displayed whengradle tasks
is called.- Specified by:
setDescription
in interfaceTask
- Overrides:
setDescription
in classorg.gradle.api.internal.AbstractTask
- Parameters:
description
- The description of the task. Might be null.
-
getGroup
Description copied from interface:Task
Returns the task group which this task belongs to. The task group is used in reports and user interfaces to group related tasks together when presenting a list of tasks to the user. -
setGroup
Description copied from interface:Task
Sets the task group which this task belongs to. The task group is used in reports and user interfaces to group related tasks together when presenting a list of tasks to the user. -
getDestroyables
Description copied from interface:Task
Returns the destroyables of this task.
- Specified by:
getDestroyables
in interfaceTask
- Overrides:
getDestroyables
in classorg.gradle.api.internal.AbstractTask
- Returns:
- The destroyables. Never returns null.
-
getLocalState
Description copied from interface:Task
Returns the local state of this task.- Specified by:
getLocalState
in interfaceTask
- Overrides:
getLocalState
in classorg.gradle.api.internal.AbstractTask
-
getTemporaryDir
Description copied from interface:Task
Returns a directory which this task can use to write temporary files to. Each task instance is provided with a separate temporary directory. There are no guarantees that the contents of this directory will be kept beyond the execution of the task.
- Specified by:
getTemporaryDir
in interfaceTask
- Overrides:
getTemporaryDir
in classorg.gradle.api.internal.AbstractTask
- Returns:
- The directory. Never returns null. The directory will already exist.
-
setMustRunAfter
Description copied from interface:Task
Specifies the set of tasks that this task must run after.
task taskY { mustRunAfter = ["taskX1", "taskX2"] }
For each supplied task, this action adds a task 'ordering', and does not specify a 'dependency' between the tasks. As such, it is still possible to execute 'taskY' without first executing the 'taskX' in the example.
See here for a description of the types of objects which can be used to specify an ordering relationship.
- Specified by:
setMustRunAfter
in interfaceTask
- Overrides:
setMustRunAfter
in classorg.gradle.api.internal.AbstractTask
- Parameters:
mustRunAfterTasks
- The set of task paths this task must run after.
-
mustRunAfter
Description copied from interface:Task
Specifies that this task must run after all of the supplied tasks.
task taskY { mustRunAfter "taskX" }
For each supplied task, this action adds a task 'ordering', and does not specify a 'dependency' between the tasks. As such, it is still possible to execute 'taskY' without first executing the 'taskX' in the example.
See here for a description of the types of objects which can be used to specify an ordering relationship.
- Specified by:
mustRunAfter
in interfaceTask
- Overrides:
mustRunAfter
in classorg.gradle.api.internal.AbstractTask
- Parameters:
paths
- The tasks this task must run after.- Returns:
- the task object this method is applied to
-
getMustRunAfter
Description copied from interface:Task
Returns tasks that this task must run after.
- Specified by:
getMustRunAfter
in interfaceTask
- Overrides:
getMustRunAfter
in classorg.gradle.api.internal.AbstractTask
- Returns:
- The tasks that this task must run after. Returns an empty set if this task has no tasks it must run after.
-
setFinalizedBy
Description copied from interface:Task
Specifies the set of finalizer tasks for this task.
task taskY { finalizedBy = ["taskX1", "taskX2"] }
See here for a description of the types of objects which can be used to specify a finalizer task.
- Specified by:
setFinalizedBy
in interfaceTask
- Overrides:
setFinalizedBy
in classorg.gradle.api.internal.AbstractTask
- Parameters:
finalizedByTasks
- The tasks that finalize this task.
-
finalizedBy
Description copied from interface:Task
Adds the given finalizer tasks for this task.
task taskY { finalizedBy "taskX" }
See here for a description of the types of objects which can be used to specify a finalizer task.
- Specified by:
finalizedBy
in interfaceTask
- Overrides:
finalizedBy
in classorg.gradle.api.internal.AbstractTask
- Parameters:
paths
- The tasks that finalize this task.- Returns:
- the task object this method is applied to
-
getFinalizedBy
Description copied from interface:Task
Returns tasks that finalize this task.
- Specified by:
getFinalizedBy
in interfaceTask
- Overrides:
getFinalizedBy
in classorg.gradle.api.internal.AbstractTask
- Returns:
- The tasks that finalize this task. Returns an empty set if there are no finalising tasks for this task.
-
shouldRunAfter
Description copied from interface:Task
Specifies that this task should run after all of the supplied tasks.
task taskY { shouldRunAfter "taskX" }
For each supplied task, this action adds a task 'ordering', and does not specify a 'dependency' between the tasks. As such, it is still possible to execute 'taskY' without first executing the 'taskX' in the example.
See here for a description of the types of objects which can be used to specify an ordering relationship.
- Specified by:
shouldRunAfter
in interfaceTask
- Overrides:
shouldRunAfter
in classorg.gradle.api.internal.AbstractTask
- Parameters:
paths
- The tasks this task should run after.- Returns:
- the task object this method is applied to
-
setShouldRunAfter
Description copied from interface:Task
Specifies the set of tasks that this task should run after.
task taskY { shouldRunAfter = ["taskX1", "taskX2"] }
For each supplied task, this action adds a task 'ordering', and does not specify a 'dependency' between the tasks. As such, it is still possible to execute 'taskY' without first executing the 'taskX' in the example.
See here for a description of the types of objects which can be used to specify an ordering relationship.
- Specified by:
setShouldRunAfter
in interfaceTask
- Overrides:
setShouldRunAfter
in classorg.gradle.api.internal.AbstractTask
- Parameters:
shouldRunAfterTasks
- The set of task paths this task should run after.
-
getShouldRunAfter
Description copied from interface:Task
Returns tasks that this task should run after.
- Specified by:
getShouldRunAfter
in interfaceTask
- Overrides:
getShouldRunAfter
in classorg.gradle.api.internal.AbstractTask
- Returns:
- The tasks that this task should run after. Returns an empty set if this task has no tasks it must run after.
-
getTimeout
Description copied from interface:Task
The timeout of this task.
task myTask { timeout = Duration.ofMinutes(10) }
The Thread executing this task will be interrupted if the task takes longer than the specified amount of time to run. In order for a task to work properly with this feature, it needs to react to interrupts and must clean up any resources it opened.
By default, tasks never time out.
- Specified by:
getTimeout
in interfaceTask
- Overrides:
getTimeout
in classorg.gradle.api.internal.AbstractTask
-
usesService
Description copied from interface:Task
Registers aBuildService
that is used by this task soits constraint on parallel execution
can be honored.This is not necessary for task properties declared as
ServiceReference
s.- Specified by:
usesService
in interfaceTask
- Overrides:
usesService
in classorg.gradle.api.internal.AbstractTask
- Parameters:
service
- The service provider.- See Also:
-
getState
public org.gradle.api.internal.tasks.TaskStateInternal getState()Description copied from interface:Task
Returns the execution state of this task. This provides information about the execution of this task, such as whether it has executed, been skipped, has failed, etc. -
getTaskDependencies
public org.gradle.api.internal.tasks.TaskDependencyInternal getTaskDependencies()Description copied from interface:Task
Returns a
TaskDependency
which contains all the tasks that this task depends on.Calling this method from a task action is not supported when configuration caching is enabled.
- Specified by:
getTaskDependencies
in interfaceTask
- Overrides:
getTaskDependencies
in classorg.gradle.api.internal.AbstractTask
- Returns:
- The dependencies of this task. Never returns null.
-
onlyIf
Description copied from interface:Task
Execute the task only if the given closure returns true. The closure will be evaluated at task execution time, not during configuration. The closure will be passed a single parameter, this task. If the closure returns false, the task will be skipped.
You may add multiple such predicates. The task is skipped if any of the predicates return false.
Typical usage:
myTask.onlyIf { isProductionEnvironment() }
-
setOnlyIf
Description copied from interface:Task
Execute the task only if the given closure returns true. The closure will be evaluated at task execution time, not during configuration. The closure will be passed a single parameter, this task. If the closure returns false, the task will be skipped.
The given predicate replaces all such predicates for this task.
-
getLogging
Description copied from interface:Task
Returns theLoggingManager
which can be used to receive logging and to control the standard output/error capture for this task. By default, System.out is redirected to the Gradle logging system at the QUIET log level, and System.err is redirected at the ERROR log level.- Specified by:
getLogging
in interfaceTask
- Overrides:
getLogging
in classorg.gradle.api.internal.AbstractTask
- Returns:
- the LoggingManager. Never returns null.
-
getInputs
public org.gradle.api.internal.TaskInputsInternal getInputs()Description copied from interface:Task
Returns the inputs of this task.
-
getOutputs
public org.gradle.api.internal.TaskOutputsInternal getOutputs()Description copied from interface:Task
Returns the outputs of this task.
- Specified by:
getOutputs
in interfaceTask
- Specified by:
getOutputs
in interfaceorg.gradle.api.internal.TaskInternal
- Overrides:
getOutputs
in classorg.gradle.api.internal.AbstractTask
- Returns:
- The outputs. Never returns null.
-
doFirst
Description copied from interface:Task
Adds the given closure to the beginning of this task's action list. The closure is passed this task as a parameter when executed.
-
doLast
Description copied from interface:Task
Adds the given closure to the end of this task's action list. The closure is passed this task as a parameter when executed.
-
configure
Description copied from interface:Task
Applies the statements of the closure against this task object. The delegate object for the closure is set to this task.
- Specified by:
configure
in interfaceConfigurable<Task>
- Specified by:
configure
in interfaceTask
- Overrides:
configure
in classorg.gradle.api.internal.AbstractTask
- Parameters:
closure
- The closure to be applied (can be null).- Returns:
- This task
-
getExtensions
Description copied from interface:ExtensionAware
The container of extensions.- Specified by:
getExtensions
in interfaceExtensionAware
- Overrides:
getExtensions
in classorg.gradle.api.internal.AbstractTask
-