Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

What is Gradle DAG (Directed Acyclic Graph)?

What is DAG (Directed Acyclic Graph)
In computer science and mathematics, a directed acyclic graph (DAG) is a graph that is directed and without cycles connecting the other edges. This means that it is impossible to traverse the entire graph starting at one edge. The edges of the directed graph only go one way. The graph is a topological sorting, where each node is in a certain order.

Understanding DAG (Directed Acyclic Graph) in Gradle

Core of Gradle is a language for dependency based programming. In Gradle terms this means that you can define tasks and dependencies between tasks. Gradle guarantees that these tasks are executed in the order of their dependencies, and that each task is executed only once. These tasks form a Directed Acyclic Graph. Gradle builds the complete dependency graph before any task is executed. Gradle models its builds as Directed Acyclic Graphs (DAGs) of tasks (units of work).

What this means is that a build essentially configures a set of tasks and wires them together — based on their dependencies — to create that DAG. Once the task graph has been created, Gradle determines which tasks need to be run in which order and then proceeds to execute them.

In order to understand “Directed Acyclic Graphs” DAG, we need to understand a Gradle build lifecycle.

Gradle build lifecycle consist of three phases: initialization, configuration, and execution:

The initialization phase with settings.gradle

During Initialization, Gradle decides which projects are to participate in the build.

In this phase, Gradle tries to identify all the projects involved in the build process. It is very important for Gradle to know whether it’s a Single-project build or a Multi-project build. In a Multi-project build there are several projects to evaluate. Hence, several build scripts. Gradle looks at the settings.gradle file in order to identify the different projects. At the end of the initialization phase, Gradle creates an instance of org.gradle.api.Project corresponding to each of these projects.

The configuration phase with build.gradle

During Configuration, task objects are assembled into an internal object model, usually called the DAG (for directed acyclic graph).

During this phase, Gradle executes the build script of each project identified in the previous phase. Actually, it is very important to know that just because we say “Gradle executes the build scripts” does not mean that the Tasks in those build scripts are executed too. Instead, after evaluating those scripts as simple Groovy scripts and identify the tasks in it, Gradle builds a Directed Acyclic Graph (DAG) of task objects. A DAG is a mathematical algorithm for representing a graph that contains no cycles. The “directed” term means each dependency arrow goes in one direction. “Acyclic” means that there are no loops in the graph.

The execution phase with doLast and doFirst

During Execution, build tasks are executed in the order required by their dependency relationships.

In nutshell,

  • If you put a code in the settings.gradle file, it is evaluated in the initialization phase
  • The code in your build script files that are not related to actions of your tasks are evaluated in the configuration phase.
  • The code in the actual actions of your tasks like the doLast closures of your tasks are evaluated in the execution phase.

Single project build Example of Gradle DAG (Directed Acyclic Graph)

Output of gradle test

> gradle test

E:\gra>gradle test
This is executed during the initialization phase.

> Configure project :
This is executed during the configuration phase.
This is also executed during the configuration phase.
This is executed during the execution phase.

> Task :test
This is executed during the execution phase with doFirst
This is executed during the execution phase with doLast

BUILD SUCCESSFUL in 1s
1 actionable task: 1 executedCode language: JavaScript (javascript)

To list task dependencies in Gradle?

$ gradle dependencies - Displays all dependencies declared in root project 'gra'.
$ gradle dependencyInsight - Displays the insight into a specific dependency in root project 'gra'.
$ gradle dependentComponents - Displays the dependent components of components in root project 'gra'. [incubating]

Only lists dependencies in master project  
$ gradle dependencies
$ gradle dependencies --scan

Lists subproject dependencies in project
$  gradle :<subproject>:dependencies
$ ./gradlew app:dependencies	# where app is your project module.

If you want to see dependencies on project and all subprojects use in your top-level build.gradle:
subprojects {
    task listAllDependencies(type: DependencyReportTask) {}
}

Then call gradle:
$ gradle listAllDependenciesCode language: PHP (php)

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

What is Gradle and use cases of Gradle?

What is Gradle? Gradle is an open-source build automation tool that is designed to be flexible, powerful, and highly customizable. It is often used for building, testing,…

Read More

What is Gradle and How it works? An Overview and Its Use Cases?

What is Gradle? Gradle is a popular choice for Java developers who want flexibility and performance in a build automation tool. Gradle is a modern automation tool…

Read More

Top 50 interview questions and answers of Gradle

Short description about Gradle Gradle is an open-source build automation tool that is designed to be flexible enough to build almost any type of software. Moving to…

Read More

Top Gradle interview questions and answers

What is Gradle build tool? Gradle is a build automation tool based on Groovy and Kotlin. It’s open-source and flexible enough to build almost any type of software….

Read More

What is settings.gradle in Gradle?

A gradle build has three important files. build.gradle, gradle.properties and settings.gradle Gradle build lifecycle consist of three phases: initialization, configuration, and execution. settings.gradle get evaluated in the…

Read More

Gradle Interview questions and Answer Part 1

What are the parts of the task lifecycle? A. Configuration, Execution B. Initialization, Configuration, Execution C. Initialization, Configuration, Execution, Finalization D. Execution Ans: B. Initialization, Configuration, Execution…

Read More