Gradle is a Build tool.What is Gradle
But before understanding Gradle, we need to understand what is a build tool 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:
- Downloading dependencies
- Compiling source code into executable code
- Packing that executable code and generating APK or executable form
- Running different tests etc.
Build tools are also called build systems.
In Android, the Build system takes all the source files (like .java, .kt, or .xml), then apply the appropriate compilation process (like using a 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, and why layouts must go into layout the directory, that is because of these build systems. The build system uses some naming convention, the design in such a way that they perform their operations based on that naming convention.
While generating APK, whenever the 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 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 track what needs to be built, in which sequence, and what dependencies are there in the building process. That is why we need 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. It is 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.
Gradle supports all major IDEs like Android Studio, IntelliJ, Visual Studio, Eclipse, Xcode, etc. You can also invoke it via a command line terminal.
Why did Google choose Gradle for android?
There are many build systems there in the market like Maven, Ant, Atlassian Bamboo, CircleCi, TeamCity, Travis Ci, etc.
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:
- User Experience
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 executable 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 likes to work with terminal. 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 and interactive web-based UI for debugging and optimizing builds. So, guys, that’s it for a Gradle. Feel free to tell me if I missed something.