Gradle Task: Difference between revisions
Line 82: | Line 82: | ||
<font color=darkgray>TODO: https://docs.gradle.org/current/dsl/#N10376</font> | <font color=darkgray>TODO: https://docs.gradle.org/current/dsl/#N10376</font> | ||
=To Deplete= | |||
<font color=darkgray> | |||
build.gradle allows declaring closures to react to various [[Build.gradle#Respond_to_Task_Lifecycle_Events|events related to tasks lifecycle]]. Also see [[#Task_Container|Task Container]]. | |||
<syntaxhighlight lang='groovy'> | |||
task configured { | |||
// will be run during the configuration phase | |||
} | |||
</syntaxhighlight> | |||
<syntaxhighlight lang='groovy'> | |||
task doFirst { | |||
} | |||
</syntaxhighlight> | |||
<syntaxhighlight lang='groovy'> | |||
task doLast { | |||
} | |||
</syntaxhighlight> | |||
{{Internal|Gradle Custom Task|Custom Tasks}} | |||
</font> |
Revision as of 23:23, 17 May 2018
External
Internal
Overview
A task is a core Gradle concept. It represents a single atomic piece of work for a build, such as compiling classes or generating javadoc. A build consists in executing a sequence of tasks in succession. Gradle computes the Directed Acyclic Graph of to be executed in order to fulfill the tasks specified on command line, and then executes them honoring inter-task dependencies and insuring the fact that a task is executed only once. Gradle builds the complete dependency graph before any tasks is executed.
All tasks known to a build can be displayed with:
gradle tasks
The tasks known to a specific project can be displayed with:
gradle :<project-path>:tasks
Task Sources
Default Tasks
Any build comes with a number of pre-defined default tasks, regardless on whether plugins have been applied or not. They are available below:
gradle dependencies
Displays all dependencies (classpath) for various dependency configurations of the root project or a sub-project. More details in:
gradle dependencyInsight
Displays the insight into a specific dependency. More details in:
gradle dependentComponents
Displays the dependent components of components in project ':subproject-A'.
gradle model
Displays the configuration model of project ':subproject-A'.
gradle projects
Displays the sub-projects of project ':subproject-A'.
gradle properties
Displays the properties of project ':subproject-A'.
gradle tasks
Displays the tasks runnable from project ':subproject-A'.
gradle buildEnvironment
Displays all buildscript dependencies declared in project ':subproject-A'.
gradle components
Displays the components produced by project ':subproject-A'.
Tasks From Plugins
Plugins that have been applied to the project may come with their own tasks. This is a non-exhaustive list:
Explicit Task Declaration
Tasks may be explicitly declared in build.gradle using Project's task() method. As an example, of the simplest possible task declarations is:
task sample {
println 'this is a simple task'
}
A task declared as above will be executed during the configuration phase, not execution. Investigate, this seems odd.
Task Types
TODO: https://docs.gradle.org/current/dsl/#N10376
To Deplete
build.gradle allows declaring closures to react to various events related to tasks lifecycle. Also see Task Container.
task configured {
// will be run during the configuration phase
}
task doFirst {
}
task doLast {
}