At its core, Gradle is a Java application for creating deployment files which runs in the JVM (Java Virtual Machine) allowing it to leverage the speed and efficiency that the JVM has refined over its 20 year life. To avoid some of the complexity of coding in Java, Gradle uses the Groovy programming language to allow quick and simple customization to the core features of Gradle.
- [Man] Let's talk about Gradle from the bottom up. And by that I mean let's take a lower-level technical look at Gradle and see what it really consists of. And we'll focus on the six key features of Gradle. First feature is that Gradle needs a build file, so it needs both a human and machine readable instruction file. So, human readable so that we can create it, machine readable so that Gradle can process it. Now partly it's declarative, partly it's programmatic. So, we'll use a DSL, a domain specific language that'll give us kind of a high-level way of describing the build, and then we'll also have Groovy, which is a low-level language for describing the build that in even greater level of detail, and it's also possible to use an alternate Java virtual machine language like Kotlin, and the default name for the build file is build.gradle.
The second key feature of Gradle is that it will construct a graph of the tasks. So tasks in Gradle are the detailed build steps, and there are usually many, many tasks to create a build. Gradle parses the build.gradle file, in other words it reads that build.gradle file and gets the tasks from that. And then it creates a DAG, a directed acyclic graph, and this is one of those computer science-y words that's really not that complicated, but sounds pretty impressive.
What actually is a DAG? Well, it's really just a set of tasks that are directed, that means they only go in one direction, there's task one, task two, task three, and it's acyclic, and what that means it doesn't repeat itself, it doesn't go back in a cycle. So it constructs the graph of tasks and now Gradle knows what to do. The third key feature of Gradle is to actually execute those tasks, so it executes the tasks in the graph in the order that it has figured out they have to be executed.
Now, each task gets some input and produces some output that's used by the next task. Gradle saves the output of each task, and this is very important for improving the performance of Gradle, because when we rerun the build, which we'll do quite often, if the output of a task is the same, we don't need to rerun the next task then, since it's getting the same input and it would produce the exact same output again, so in that case we can skip the task, move on to the next one for when something's actually changed.
Fourth key feature of Gradle is that it manages dependencies, so remember dependencies are external Java code and libraries that we didn't write. Dependencies themselves may have additional internal dependencies, so in other words, there might be an open source library that we wanna use that is using other open source libraries. These internal dependencies are often referred to as transitive dependencies, so Gradle will manage those for us also. And then finally it will get the right version of the dependency, so many open source libraries have existed for quite a while and over that time new versions have come out, so we need to make sure that we get the right version and if we wanna get a new version we can tell Gradle to do that.
Fifth key feature is that Gradle uses repositories. What's a repository? It's really just a storehouse of these external dependencies, and these repositories may live out on the open internet or they may be within our enterprise, maybe they're only within our company and we can share them with other people in the company, or they may be just on our local machine. The sixth and final key feature of Gradle is that it's self-updating. And it's self-updating in two ways. First, Gradle can retrieve new versions of Gradle itself, so Gradle, like any other open source project is changing and mutating over time, and as those new versions become available we can get them automatically.
Second aspect of this is that because we have all these dependencies that might change over time, Gradle can monitor and retrieve the new versions of those dependencies.
- The purpose of Gradle
- Building a Java project with Gradle
- Adding a dependency to a project
- Creating a library module
- The Gradle project structure
- Creating new Gradle tasks
- Profiling and using the Gradle cloud