allprojects { }
artifacts { }
buildscript { }
configurations { }
dependencies { }
repositories { }
sourceSets { }
subprojects { }
publishing { }
Project
Task
Gradle
Settings
IncludedBuild
Script
JavaToolChain
SourceSet
SourceSetOutput
IncrementalTaskInputs
Configuration
ResolutionStrategy
ArtifactResolutionQuery
ComponentSelection
ComponentSelectionRules
ConventionProperty
GradlePluginPortal
ExtensionAware
ExtraPropertiesExtension
PublishingExtension
IvyPublication
IvyArtifact
IvyArtifactSet
IvyModuleDescriptorSpec
IvyPluginRepository
MavenPublication
MavenArtifact
MavenArtifactSet
MavenPom
MavenPluginRepository
PluginDependenciesSpec
PluginDependencySpec
PluginManagementSpec
PluginRepositoriesSpec
PluginRepository
ResourceHandler
TextResourceFactory
ConfigurationContainer
RepositoryHandler
DependencyHandler
ArtifactHandler
BuildCacheConfiguration
DirectoryBuildCache
HttpBuildCache
TaskReportTask
ProjectReportTask
DependencyReportTask
DependencyInsightReportTask
PropertyReportTask
ComponentReport
DependentComponentsReport
ModelReport
AntlrTask
BuildEnvironmentReportTask
Checkstyle
CodeNarc
CompareGradleBuilds
Copy
CreateStartScripts
Delete
Ear
Exec
FindBugs
GenerateIvyDescriptor
GenerateMavenPom
GenerateBuildDashboard
GradleBuild
GroovyCompile
Groovydoc
HtmlDependencyReportTask
JacocoReport
JacocoMerge
JacocoCoverageVerification
Jar
JavaCompile
Javadoc
JavaExec
JDepend
JettyRun
JettyRunWar
JettyStop
Pmd
PublishToIvyRepository
PublishToMavenRepository
ScalaCompile
ScalaDoc
InitBuild
Sign
Sync
Tar
Test
TestReport
Upload
War
Wrapper
WriteProperties
Zip
CustomizableHtmlReport
SingleFileReport
DirectoryReport
FindBugsXmlReport
Report
Reporting
ReportContainer
ReportingExtension
EclipseModel
EclipseProject
EclipseClasspath
EclipseJdt
EclipseWtp
EclipseWtpComponent
EclipseWtpFacet
IdeaModel
IdeaProject
IdeaModule
IdeaWorkspace
XmlFileContentMerger
FileContentMerger
GenerateEclipseProject
GenerateEclipseClasspath
GenerateEclipseJdt
GenerateEclipseWtpComponent
GenerateEclipseWtpFacet
GenerateIdeaModule
GenerateIdeaProject
GenerateIdeaWorkspace
PrebuiltLibrary
PrebuiltSharedLibraryBinary
PrebuiltStaticLibraryBinary
NativeComponentSpec
NativeExecutableSpec
NativeLibrarySpec
NativeTestSuiteSpec
CUnitTestSuiteSpec
GoogleTestTestSuiteSpec
NativeBinarySpec
NativeExecutableBinarySpec
NativeLibraryBinarySpec
SharedLibraryBinarySpec
StaticLibraryBinarySpec
NativeTestSuiteBinarySpec
CUnitTestSuiteBinarySpec
GoogleTestTestSuiteBinarySpec
NativePlatform
BuildType
Flavor
Gcc
Clang
VisualCpp
AssemblerSourceSet
CSourceSet
CppSourceSet
ObjectiveCSourceSet
ObjectiveCppSourceSet
WindowsResourceSet
VisualStudioProject
VisualStudioSolution
NativeExecutable
NativeLibrary
NativeBinary
NativeExecutableBinary
SharedLibraryBinary
StaticLibraryBinary
CppCompile
CCompile
Assemble
ObjectiveCCompile
ObjectiveCppCompile
WindowsResourceCompile
LinkExecutable
LinkSharedLibrary
CreateStaticLibrary
InstallExecutable
RunTestExecutable
API Documentation: | Task |
---|
ATask
represents a single atomic piece of work for a build, such as compiling classes or generatingjavadoc.
Each task belongs to aProject
. You can use the various methods onTaskContainer
to create and lookup task instances. For example,TaskContainer.create(java.lang.String)
creates an empty task with the given name. You can also use thetask
keyword in your build file:
task myTasktask myTask { configure closure }task myTask(type: SomeType)task myTask(type: SomeType) { configure closure }
Each task has a name, which can be used to refer to the task within its owning project, and a fully qualifiedpath, which is unique across all tasks in all projects. The path is the concatenation of the owning project's pathand the task's name. Path elements are separated using the:
character.
ATask
is made up of a sequence ofAction
objects. When the task is executed, each of theactions is executed in turn, by callingAction.execute(T)
. You can add actions to a task by callingTask.doFirst(org.gradle.api.Action)
orTask.doLast(org.gradle.api.Action)
.
Groovy closures can also be used to provide a task action. When the action is executed, the closure is called withthe task as parameter. You can add action closures to a task by callingTask.doFirst(groovy.lang.Closure)
orTask.doLast(groovy.lang.Closure)
.
There are 2 special exceptions which a task action can throw to abort execution and continue without failing thebuild. A task action can abort execution of the action and continue to the next action of the task by throwing aStopActionException
. A task action can abort execution of the task and continue to thenext task by throwing aStopExecutionException
. Using these exceptions allows you tohave precondition actions which skip execution of the task, or part of the task, if not true.
A task may have dependencies on other tasks or might be scheduled to always run after another task.Gradle ensures that all task dependencies and ordering rules are honored when executing tasks, so that the task is executed afterall of its dependencies and any "must run after" tasks have been executed.
Dependencies to a task are controlled usingTask.dependsOn(java.lang.Object[])
orTask.setDependsOn(java.lang.Iterable)
,andTask.mustRunAfter(java.lang.Object[])
,Task.setMustRunAfter(java.lang.Iterable)
,Task.shouldRunAfter(java.lang.Object[])
andTask.setShouldRunAfter(java.lang.Iterable)
are used to specify ordering between tasks. You can use objects of any ofthe following types to specify dependencies and ordering:
String
,CharSequence
orgroovy.lang.GString
task path or name. A relative path is interpreted relative to the task'sProject
. Thisallows you to refer to tasks in other projects.Task
.Task
as parameter. It may return any of the types listed here. Itsreturn value is recursively converted to tasks. Anull
return value is treated as an empty collection.TaskDependency
object.Buildable
object.Iterable
,Collection
,Map
or array. May contain any of the types listed here. The elements of theiterable/collection/map/array are recursively converted to tasks.Callable
. Thecall()
method may return any of the types listed here. Its return value isrecursively converted to tasks. Anull
return value is treated as an empty collection.ATask
has 4 'scopes' for properties. You can access these properties by name from the build file or bycalling theTask.property(java.lang.String)
method. You can change the value of these properties by calling theTask.setProperty(java.lang.String, java.lang.Object)
method.
Task
object itself. This includes any property getters and setters declared by theTask
implementation class. The properties of this scope are readable or writable based on the presence of thecorresponding getter and setter methods.Convention
object. The properties of this scope may be readable or writable, depending on the convention objects.APlugin
may add methods to aTask
using itsConvention
object.
By default, tasks are not executed in parallel.Parallel execution can be enabled by the--parallel
flag when the build is initiated.In parallel mode, the tasks of different projects (i.e. in a multi project build) are able to be executed in parallel.If a task is annotated withParallelizableTask
, it may also be executed in parallel with other tasks of the same project.SeeParallelizableTask
for more details on writing parallelizable tasks.
Property | Description |
actions | The sequence of |
ant | The |
convention | The |
dependsOn | The dependencies of this task. |
description | The description of this task. |
didWork | Checks if the task actually did any work. Even if a Task executes, it may determine that it has nothing todo. For example, a compilation task may determine that source files have not changed since the last time a thetask was run. |
enabled | Returns if this task is enabled or not. |
extensions | The container of extensions. |
finalizedBy | Incubating Returns tasks that finalize this task. |
group | The task group which this task belongs to. The task group is used in reports and user interfaces togroup related tasks together when presenting a list of tasks to the user. |
inputs | The inputs of this task. |
logger | The logger for this task. You can use this in your build file to write log messages. |
logging | The |
mustRunAfter | Incubating Returns tasks that this task must run after. |
name | The name of this task. The name uniquely identifies the task within its |
outputs | The outputs of this task. |
path | The path of the task, which is a fully qualified name for the task. The path of a task is the path ofits |
project | The |
state | The execution state of this task. This provides information about the execution of this task, such aswhether it has executed, been skipped, has failed, etc. |
taskDependencies | Returns a |
temporaryDir | Returns a directory which this task can use to write temporary files to. Each task instance is provided with aseparate temporary directory. There are no guarantees that the contents of this directory will be kept beyond theexecution of the task. |
Method | Description |
deleteAllActions() | Removes all the actions of this task. |
dependsOn(paths) | Adds the given dependencies to this task. Seehere for a description of the typesof objects which can be used as task dependencies. |
doFirst(action) | Adds the given closure to the beginning of this task's action list. The closure is passed this task as aparameter when executed. |
doFirst(action) | Adds the given |
doLast(action) | Adds the given closure to the end of this task's action list. The closure is passed this task as a parameterwhen executed. |
doLast(action) | Adds the given |
finalizedBy(paths) | Incubating Adds the given finalizer tasks for this task. |
hasProperty(propertyName) | Determines if this task has the given property. Seehere for details of theproperties which are available for a task. |
leftShift(action) | Deprecated Adds the given closure to the end of this task's action list. The closure is passed this task as a parameterwhen executed. You can call this method from your build script using the << left shift operator. |
mustRunAfter(paths) | Incubating Specifies that this task must run after all of the supplied tasks. |
onlyIf(onlyIfClosure) | Execute the task only if the given closure returns true. The closure will be evaluated at task executiontime, not during configuration. The closure will be passed a single parameter, this task. If the closure returnsfalse, the task will be skipped. |
onlyIf(onlyIfSpec) | Execute the task only if the given spec is satisfied. The spec will be evaluated at task execution time, notduring configuration. If the Spec is not satisfied, the task will be skipped. |
property(propertyName) | Returns the value of the given property of this task. This method locates a property as follows: |
setProperty(name, value) | Sets a property of this task. This method searches for a property with the given name in the followinglocations, and sets the property on the first location where it finds the property. |
The sequence ofAction
objects which will be executed by this task, in the order ofexecution.
AntBuilder
ant
(read-only)TheAntBuilder
for this task. You can use this in your build file to execute anttasks.
Convention
convention
(read-only)TheConvention
object for this task. APlugin
can use the convention object tocontribute properties and methods to this task.
String
description
The description of this task.
Checks if the task actually did any work. Even if a Task executes, it may determine that it has nothing todo. For example, a compilation task may determine that source files have not changed since the last time a thetask was run.
ExtensionContainer
extensions
(read-only)The container of extensions.
TaskDependency
finalizedBy
Note: This property isincubating and may change in a future version of Gradle.
Returns tasks that finalize this task.
String
group
The task group which this task belongs to. The task group is used in reports and user interfaces togroup related tasks together when presenting a list of tasks to the user.
TaskInputs
inputs
(read-only)The inputs of this task.
Logger
logger
(read-only)The logger for this task. You can use this in your build file to write log messages.
LoggingManager
logging
(read-only)TheLoggingManager
which can be used to control the logging level andstandard output/error capture for this task. By default, System.out is redirected to the Gradle logging system atthe QUIET log level, and System.err is redirected at the ERROR log level.
TaskDependency
mustRunAfter
Note: This property isincubating and may change in a future version of Gradle.
Returns tasks that this task must run after.
String
name
(read-only)The name of this task. The name uniquely identifies the task within itsProject
.
TaskOutputs
outputs
(read-only)The outputs of this task.
String
path
(read-only)The path of the task, which is a fully qualified name for the task. The path of a task is the path ofitsProject
plus the name of the task, separated by:
.
TaskState
state
(read-only)The execution state of this task. This provides information about the execution of this task, such aswhether it has executed, been skipped, has failed, etc.
TaskDependency
taskDependencies
(read-only)Returns aTaskDependency
which contains all the tasks that this task depends on.
File
temporaryDir
(read-only)Returns a directory which this task can use to write temporary files to. Each task instance is provided with aseparate temporary directory. There are no guarantees that the contents of this directory will be kept beyond theexecution of the task.
Task
deleteAllActions
()Removes all the actions of this task.
Adds the given dependencies to this task. Seehere for a description of the typesof objects which can be used as task dependencies.
Adds the given closure to the beginning of this task's action list. The closure is passed this task as aparameter when executed.
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. The closure is passed this task as a parameterwhen executed.
Note: This method isincubating and may change in a future version of Gradle.
Adds the given finalizer tasks for this task.
task taskY { finalizedBy"taskX"}
Seehere for a description of the types of objects which can be used to specifya finalizer task.
boolean
hasProperty
(String
propertyName)Determines if this task has the given property. Seehere for details of theproperties which are available for a task.
Note: This method isdeprecated and will be removed in the next major version of Gradle.
Adds the given closure to the end of this task's action list. The closure is passed this task as a parameterwhen executed. You can call this method from your build script using the << left shift operator.
Note: This method isincubating and may change in a future version of Gradle.
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.
Seehere for a description of the types of objects which can be used to specifyan ordering relationship.
void
onlyIf
(Closure
onlyIfClosure)Execute the task only if the given closure returns true. The closure will be evaluated at task executiontime, not during configuration. The closure will be passed a single parameter, this task. If the closure returnsfalse, 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{ dependsOnTaskDidWork() }
Execute the task only if the given spec is satisfied. The spec will be evaluated at task execution time, notduring 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 task.dependsOnTaskDidWork(); }});
Returns the value of the given property of this task. This method locates a property as follows:
MissingPropertyException
Sets a property of this task. This method searches for a property with the given name in the followinglocations, and sets the property on the first location where it finds the property.
enabled
project property.If the property is not found, aMissingPropertyException
is thrown.