A build process execute a graph of tasks.
Task may just be:
tasks.register("Hello") {
println("Hello")
}
gradlew Hello
Hello
Tasks themselves consist of:
A task should never call another task.
Tasks should define inputs and outputs to get the performance benefits of incremental build functionality.
When declaring the outputs of a task, make sure that the directory for writing outputs is unique among all the tasks in your project.
Intermingling or overwriting output files produced by different tasks compromises up-to-date checking causing slower builds. In turn, these filesystem changes may prevent Gradle’s build cache from properly identifying and caching what would otherwise be cacheable tasks.
Task are provided by:
Example for copy
task copy(type: Copy, group: "Custom", description: "Copies sources to the dest directory") {
from "src"
into "dest"
}
tasks.register("logInfo") {
logging.captureStandardOutput(LogLevel.INFO)
doFirst {
println("A task message which is logged at INFO level")
}
}
task echo(description: 'Default task') << {
println 'Hello'
}
defaultTasks 'echo'
gradlew tasks
# or
gradlew tasks --all
gradle :services:webservice:tasks
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
val testTask = tasks.getByName<Test>("test");
testTask.failFast = true;
tasks.test {
failFast = true;
}
gradle -q taskName
where:
gradle [-x|--exclude-task]
Ignore previously cached task results.
gradle --rerun-tasks
gradlew help --task <task>
Run the builds with all task actions disabled.
gradle [-m|--dry-run]
https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:task_dependencies
tasks.register("hello") {
doLast {
println("Hello world!")
}
}
tasks.register("intro") {
dependsOn("hello")
doLast {
println("I'm Gradle")
}
}