Gradle is a Build Tool. But before understanding Gradle, we need to understand what is build tool is and why we need one.
What is Build Tool?
The build tool is software that helps to automate the process of application creation. The build process incorporates compiling, linking, and packaging the code into executable form.
Build tools used to automate tedious tasks like:
Compiling source code into executable code
packing that executable code and generating APK or executable form
Running different tests etc.
Build tools also called build system.
In Android, the Build system takes all the source files (like
.xml), then applies an appropriate compilation process (like using Kotlin compiler for compiling
.kt files) and generates an executable package or APK.
Ever you asked yourself why Android is so strict about naming the folders? Why every resource goes into a
res directory, why layouts must go into
layout the directory, that is because of these build systems. The build system uses some naming convention, they design in such a way that they perform their operations based on that naming convention.
While generating APK, whenever a build system needs any resource, It is designed in such a way that it finds that resource in a
res directory. That’s why Android is so strict about naming the directories.
To automate these all tasks we use scripts. You can create your own build system based using shell scripting in Linux and using a batch file in Windows.
Why do we need to Build Tools?
In small projects, developers can manually create the build process. When only two or three files are there this approach worked. But in large projects, this approach cannot be worked, where it is hard to keep track of what needs to be built, in which sequence, and what dependencies are there in the building process. That is why we need to build tools because they provide a much easier, more powerful, and faster build process.
What is Gradle?
Gradle is an Open-source build tool. It is written in Java, Groovy, and Kotlin. Gradle comprises the top features of Apache Ant and Apache Maven. But it is far faster, more flexible, and more powerful than any of them.
Gradle is a JVM-based build system, which means you can write your own scripts in any JVM-based language like Java, Kotlin, Groovy, Scala, etc. Gradle also has counted in the top 20 open-source projects, Tech-Giants like Google, Adobe, LinkedIn, Netflix, and Elastic used it as a build tool for their projects.
Why did Google choose Gradle for Android?
But Google wants to make the app development process faster and easier, and at that time and today also no one is as fast and flexible as Gradle. And that is why Google choose it for the Operating System that rules 70% of the market Android.
Google choose it because of three main reasons:
Gradle is nearly twice fast as Maven in all scenarios and 100x faster for large builds using the build cache. In the above picture, you can see the performance graph of Gradle. It is not just fast it’s super-fast.
Google choose Gradle not just because it is far faster than others. But the Gradle is also very flexible. Gradle’s model is designed in such a way that it can be expanded to cover any ecosystem.
Gradle is a plugin-based build system. That means even if you have your own programming language and if you want to automate the task of generating executables from source code then you can write your own plugin in any JVM-based language like Java, Kotlin, Scala, Groovy, etc, and use it. This makes Gradle much more flexible than others.
For providing a better user experience Gradle supports a wide range of IDEs like Android Studio, IntelliJ, Eclipse, Visual Studio, Xcode, etc.
Although IDEs are important, a large number of users still like to work with terminals. That’s why Gradle provides modern CLI (Command Line Interface) that has several powerful features like ‘Gradle tasks’, command line completion, etc.
Gradle also provides build scans interactive web-based UI for debugging and optimizing builds.
So, guys, that’s it for a Gradle. Feel free to know me if I missed something. Till then Keep Coding, Keep Loving, and Catch you up in the next article.
Jai Hind, Vande Mataram 🇮🇳