Comparable<Task>
, org.gradle.api.internal.DynamicObjectAware
, org.gradle.api.internal.TaskInternal
, ExtensionAware
, Task
, org.gradle.util.Configurable<Task>
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
, OutgoingVariantsReportTask
, PluginUnderTestMetadata
, PrefixHeaderFileGenerateTask
, PublishToIvyRepository
, Sign
, StripSymbols
, SwiftCompile
, TestReport
, UnexportMainSymbol
, ValidatePlugins
, WindowsResourceCompile
, Wrapper
, WriteProperties
public class DefaultTask extends Object implements org.gradle.api.internal.TaskInternal, org.gradle.api.internal.DynamicObjectAware
DefaultTask
is the standard Task
implementation. You can extend this to implement your own task types.Task.Namer
TASK_ACTION, TASK_CONSTRUCTOR_ARGS, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE
Constructor | Description |
---|---|
DefaultTask() |
Modifier and Type | Method | Description |
---|---|---|
void |
appendParallelSafeAction(Action<? super Task> action) |
|
int |
compareTo(Task otherTask) |
|
Task |
configure(Closure closure) |
Applies the statements of the closure against this task object.
|
Task |
dependsOn(Object... paths) |
Adds the given dependencies to this task.
|
Task |
doFirst(Closure action) |
Adds the given closure to the beginning of this task's action list.
|
Task |
doFirst(String actionName,
Action<? super Task> action) |
Adds the given
Action to the beginning of this task's action list. |
Task |
doFirst(Action<? super Task> action) |
Adds the given
Action to the beginning of this task's action list. |
Task |
doLast(Closure action) |
Adds the given closure to the end of this task's action list.
|
Task |
doLast(String actionName,
Action<? super Task> action) |
Adds the given
Action to the end of this task's action list. |
Task |
doLast(Action<? super Task> action) |
Adds the given
Action to the end of this task's action list. |
Task |
finalizedBy(Object... paths) |
Adds the given finalizer tasks for this task.
|
List<Action<? super Task>> |
getActions() |
Returns the sequence of
Action objects which will be executed by this task, in the order of
execution. |
AntBuilder |
getAnt() |
Returns the
AntBuilder for this task. |
org.gradle.internal.metaobject.DynamicObject |
getAsDynamicObject() |
|
Convention |
getConvention() |
Returns the
Convention object for this task. |
Set<Object> |
getDependsOn() |
Returns the dependencies of this task.
|
String |
getDescription() |
Returns the description of this task.
|
TaskDestroyables |
getDestroyables() |
Returns the destroyables of this task.
|
boolean |
getDidWork() |
Checks if the task actually did any work.
|
boolean |
getEnabled() |
Returns if this task is enabled or not.
|
ExtensionContainer |
getExtensions() |
The container of extensions.
|
TaskDependency |
getFinalizedBy() |
Returns tasks that finalize this task.
|
String |
getGroup() |
Returns the task group which this task belongs to.
|
org.gradle.util.Path |
getIdentityPath() |
|
boolean |
getImpliesSubProjects() |
|
org.gradle.api.internal.TaskInputsInternal |
getInputs() |
Returns the inputs of this task.
|
TaskLocalState |
getLocalState() |
Returns the local state of this task.
|
Logger |
getLogger() |
Returns the logger for this task.
|
LoggingManager |
getLogging() |
Returns the
LoggingManager which can be used to receive logging and to control the
standard output/error capture for this task. |
TaskDependency |
getMustRunAfter() |
Returns tasks that this task must run after.
|
String |
getName() |
Returns the name of this task.
|
Spec<? super org.gradle.api.internal.TaskInternal> |
getOnlyIf() |
|
org.gradle.api.internal.TaskOutputsInternal |
getOutputs() |
Returns the outputs of this task.
|
String |
getPath() |
Returns the path of the task, which is a fully qualified name for the task.
|
Project |
getProject() |
Returns the
Project which this task belongs to. |
Set<Provider<? extends BuildService<?>>> |
getRequiredServices() |
|
protected org.gradle.internal.service.ServiceRegistry |
getServices() |
|
List<org.gradle.internal.resources.ResourceLock> |
getSharedResources() |
|
TaskDependency |
getShouldRunAfter() |
Returns tasks that this task should run after.
|
org.gradle.internal.logging.StandardOutputCapture |
getStandardOutputCapture() |
|
org.gradle.api.internal.tasks.TaskStateInternal |
getState() |
Returns the execution state of this task.
|
List<org.gradle.api.internal.tasks.InputChangesAwareTaskAction> |
getTaskActions() |
|
org.gradle.api.internal.tasks.TaskDependencyInternal |
getTaskDependencies() |
Returns a
TaskDependency which contains all the tasks that this task depends on. |
org.gradle.api.internal.project.taskfactory.TaskIdentity<?> |
getTaskIdentity() |
|
File |
getTemporaryDir() |
Returns a directory which this task can use to write temporary files to.
|
org.gradle.internal.Factory<File> |
getTemporaryDirFactory() |
|
Property<Duration> |
getTimeout() |
The timeout of this task.
|
boolean |
hasProperty(String propertyName) |
Determines if this task has the given property.
|
boolean |
hasTaskActions() |
|
static <T extends Task> |
injectIntoNewInstance(org.gradle.api.internal.project.ProjectInternal project,
org.gradle.api.internal.project.taskfactory.TaskIdentity<T> identity,
Callable<T> factory) |
|
boolean |
isEnabled() |
|
boolean |
isHasCustomActions() |
|
Task |
mustRunAfter(Object... paths) |
Specifies that this task must run after all of the supplied tasks.
|
void |
onlyIf(Closure onlyIfClosure) |
Execute the task only if the given closure returns true.
|
void |
onlyIf(Spec<? super Task> spec) |
Execute the task only if the given spec is satisfied.
|
void |
prependParallelSafeAction(Action<? super Task> action) |
|
Object |
property(String propertyName) |
Returns the value of the given property of this task.
|
void |
setActions(List<Action<? super Task>> replacements) |
Sets the sequence of
Action 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 |
setGroup(String group) |
Sets the task group which this task belongs to.
|
void |
setImpliesSubProjects(boolean impliesSubProjects) |
|
void |
setMustRunAfter(Iterable<?> mustRunAfterTasks) |
Specifies the set of tasks that this task must run after.
|
void |
setOnlyIf(Closure onlyIfClosure) |
Execute the task only if the given closure returns true.
|
void |
setOnlyIf(Spec<? super Task> spec) |
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.
|
TaskDependency |
shouldRunAfter(Object... paths) |
Specifies that this task should run after all of the supplied tasks.
|
void |
usesService(Provider<? extends BuildService<?>> service) |
Registers a
BuildService that is used by this task. |
public static <T extends Task> T injectIntoNewInstance(org.gradle.api.internal.project.ProjectInternal project, org.gradle.api.internal.project.taskfactory.TaskIdentity<T> identity, Callable<T> factory)
@Internal public boolean isEnabled()
public boolean getEnabled()
Task
Returns if this task is enabled or not.
getEnabled
in interface Task
Task.setEnabled(boolean)
public void setEnabled(boolean enabled)
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.
setEnabled
in interface Task
enabled
- The enabled state of this task (true or false)public AntBuilder getAnt()
Task
Returns the AntBuilder
for this task. You can use this in your build file to execute ant
tasks.
public Project getProject()
Task
Returns the Project
which this task belongs to.
getProject
in interface Task
public String getName()
Task
Returns the name of this task. The name uniquely identifies the task within its Project
.
public org.gradle.api.internal.project.taskfactory.TaskIdentity<?> getTaskIdentity()
getTaskIdentity
in interface org.gradle.api.internal.TaskInternal
public List<Action<? super Task>> getActions()
Task
Returns the sequence of Action
objects which will be executed by this task, in the order of
execution.
getActions
in interface Task
public boolean isHasCustomActions()
isHasCustomActions
in interface org.gradle.api.internal.TaskInternal
public void prependParallelSafeAction(Action<? super Task> action)
prependParallelSafeAction
in interface org.gradle.api.internal.TaskInternal
public void appendParallelSafeAction(Action<? super Task> action)
appendParallelSafeAction
in interface org.gradle.api.internal.TaskInternal
public Set<Object> getDependsOn()
Task
Returns the dependencies of this task.
getDependsOn
in interface Task
public void setDependsOn(Iterable<?> dependsOn)
Task
Sets the dependencies of this task. See here for a description of the types of objects which can be used as task dependencies.
setDependsOn
in interface Task
dependsOn
- The set of task paths.public void onlyIf(Closure onlyIfClosure)
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() }
public void onlyIf(Spec<? super Task> spec)
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(); } });
public void setOnlyIf(Spec<? super Task> spec)
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.
public void setOnlyIf(Closure onlyIfClosure)
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.
public Spec<? super org.gradle.api.internal.TaskInternal> getOnlyIf()
getOnlyIf
in interface org.gradle.api.internal.TaskInternal
public boolean getDidWork()
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.
getDidWork
in interface Task
public void setDidWork(boolean didWork)
Task
setDidWork
in interface Task
didWork
- indicates if the task did any workpublic String getPath()
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 :
.
public org.gradle.util.Path getIdentityPath()
getIdentityPath
in interface org.gradle.api.internal.TaskInternal
public Task dependsOn(Object... paths)
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.
public Task doFirst(Action<? super Task> action)
Task
Adds the given Action
to the beginning of this task's action list.
public Task doFirst(String actionName, Action<? super Task> action)
Task
Adds the given Action
to the beginning of this task's action list.
public Task doLast(Action<? super Task> action)
Task
Adds the given Action
to the end of this task's action list.
public Task doLast(String actionName, Action<? super Task> action)
Task
Adds the given Action
to the end of this task's action list.
public int compareTo(Task otherTask)
compareTo
in interface Comparable<Task>
public Logger getLogger()
Task
Returns the logger for this task. You can use this in your build file to write log messages.
public Object property(String propertyName) throws MissingPropertyException
Task
Returns the value of the given property of this task. This method locates a property as follows:
MissingPropertyException
property
in interface Task
propertyName
- The name of the property.MissingPropertyException
- When the given property is unknown.public boolean hasProperty(String propertyName)
Task
Determines if this task has the given property. See here for details of the properties which are available for a task.
hasProperty
in interface Task
propertyName
- The name of the property to locate.public void setProperty(String name, Object value)
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.
enabled
project property.MissingPropertyException
is thrown.setProperty
in interface Task
name
- The name of the propertyvalue
- The value of the propertypublic String getDescription()
Task
getDescription
in interface Task
public void setDescription(String description)
Task
gradle tasks
is called.setDescription
in interface Task
description
- The description of the task. Might be null.public String getGroup()
Task
public void setGroup(String group)
Task
public File getTemporaryDir()
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.
getTemporaryDir
in interface Task
public org.gradle.internal.Factory<File> getTemporaryDirFactory()
getTemporaryDirFactory
in interface org.gradle.api.internal.TaskInternal
public List<org.gradle.api.internal.tasks.InputChangesAwareTaskAction> getTaskActions()
getTaskActions
in interface org.gradle.api.internal.TaskInternal
public boolean hasTaskActions()
hasTaskActions
in interface org.gradle.api.internal.TaskInternal
public void setActions(List<Action<? super Task>> replacements)
Task
Sets the sequence of Action
objects which will be executed by this task.
setActions
in interface Task
replacements
- The actions.public void setMustRunAfter(Iterable<?> mustRunAfterTasks)
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.
setMustRunAfter
in interface Task
mustRunAfterTasks
- The set of task paths this task must run after.public Task mustRunAfter(Object... paths)
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.
mustRunAfter
in interface Task
paths
- The tasks this task must run after.public TaskDependency getMustRunAfter()
Task
Returns tasks that this task must run after.
getMustRunAfter
in interface Task
public void setFinalizedBy(Iterable<?> finalizedByTasks)
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.
setFinalizedBy
in interface Task
finalizedByTasks
- The tasks that finalize this task.public Task finalizedBy(Object... paths)
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.
finalizedBy
in interface Task
paths
- The tasks that finalize this task.public TaskDependency getFinalizedBy()
Task
Returns tasks that finalize this task.
getFinalizedBy
in interface Task
public TaskDependency shouldRunAfter(Object... paths)
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.
shouldRunAfter
in interface Task
paths
- The tasks this task should run after.public void setShouldRunAfter(Iterable<?> shouldRunAfterTasks)
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.
setShouldRunAfter
in interface Task
shouldRunAfterTasks
- The set of task paths this task should run after.public TaskDependency getShouldRunAfter()
Task
Returns tasks that this task should run after.
getShouldRunAfter
in interface Task
public Property<Duration> getTimeout()
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.
getTimeout
in interface Task
public Set<Provider<? extends BuildService<?>>> getRequiredServices()
getRequiredServices
in interface org.gradle.api.internal.TaskInternal
public void usesService(Provider<? extends BuildService<?>> service)
Task
BuildService
that is used by this task.usesService
in interface Task
service
- The service provider.public List<org.gradle.internal.resources.ResourceLock> getSharedResources()
getSharedResources
in interface org.gradle.api.internal.TaskInternal
public org.gradle.api.internal.tasks.TaskStateInternal getState()
Task
public org.gradle.api.internal.tasks.TaskDependencyInternal getTaskDependencies()
Task
Returns a TaskDependency
which contains all the tasks that this task depends on.
getTaskDependencies
in interface Task
public LoggingManager getLogging()
Task
LoggingManager
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.getLogging
in interface Task
public org.gradle.internal.logging.StandardOutputCapture getStandardOutputCapture()
getStandardOutputCapture
in interface org.gradle.api.internal.TaskInternal
public org.gradle.api.internal.TaskInputsInternal getInputs()
Task
Returns the inputs of this task.
public org.gradle.api.internal.TaskOutputsInternal getOutputs()
Task
Returns the outputs of this task.
getOutputs
in interface Task
getOutputs
in interface org.gradle.api.internal.TaskInternal
public TaskDestroyables getDestroyables()
Task
Returns the destroyables of this task.
getDestroyables
in interface Task
public TaskLocalState getLocalState()
Task
getLocalState
in interface Task
public Task doFirst(Closure action)
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.
public Task doLast(Closure action)
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.
public Task configure(Closure closure)
Task
Applies the statements of the closure against this task object. The delegate object for the closure is set to this task.
@Internal public ExtensionContainer getExtensions()
ExtensionAware
getExtensions
in interface ExtensionAware
public Convention getConvention()
Task
Returns the Convention
object for this task. A Plugin
can use the convention object to
contribute properties and methods to this task.
getConvention
in interface Task
@Internal protected org.gradle.internal.service.ServiceRegistry getServices()
@Internal public org.gradle.internal.metaobject.DynamicObject getAsDynamicObject()
getAsDynamicObject
in interface org.gradle.api.internal.DynamicObjectAware
public boolean getImpliesSubProjects()
getImpliesSubProjects
in interface org.gradle.api.internal.TaskInternal
public void setImpliesSubProjects(boolean impliesSubProjects)
setImpliesSubProjects
in interface org.gradle.api.internal.TaskInternal