A task in Gradle is the fundamental unit of work in the build system. Tasks perform actions such as compiling code, running tests, or packaging an application. They can be simple, like printing a message, or complex, like building an entire project.
Notes
Tasks can have dependencies on other tasks.
Tasks execute specific actions in a project’s lifecycle.
Notes
Gradle Lifecycle
Gradle Life cycle.
Gradle tasks go through several phases:
Initialization: Determines which project and tasks will be part of the build.
Tasks can depend on other tasks. Gradle will ensure that all dependent tasks are executed in the proper order.
dependsOn (inter task dependency)
dependsOn (inter task dependency)
Gradle Inter-Task Dependency: dependsOn
dependsOn in Gradle defines a dependency between tasks, ensuring one task runs before another. When a task declares dependsOn, Gradle guarantees that the dependent task is executed first.
dependsOn ensures tasks execute in the correct order by defining dependencies. It’s commonly used to ensure tasks that rely on outputs from other tasks run after their dependencies complete.
Usage:
Use dependsOn to specify that a task depends on one or more other tasks.
Gradle will always execute the dependent tasks before the task that declares the dependency.
Example:
tasks.register("compile") { doLast { println("Compiling code...") }}tasks.register("build-stuff") { dependsOn("compile") // 'build' will run after 'compile' doLast { println("Building project...") }}
Glass thought Sandbox Snapshot
Command to reproduce:
gt.sandbox.checkout.commit ef515ba \&& cd "${GT_SANDBOX_REPO}" \&& cmd.run.announce "./gradlew build-stuff"