Reviewing Your Gradle Scripts

In the discussion of Android Studio, this book has mentioned something called “Gradle”, without a lot of explanation.

In this chapter, the mysteries of Gradle will be revealed to you.

(well, OK, some of the mysteries…)

Gradle: The Big Questions

First, let us “set the stage” by examining what this is all about, through a series of fictionally-asked questions (FAQs).

What is Gradle?

Gradle is software for building software, otherwise known as “build automation software” or “build systems”. You may have used other build systems before in other environments, such as make (C/C++), rake (Ruby), Ant (Java), Maven (Java), etc.

These tools know — via intrinsic capabilities and rules that you teach them — how to determine what needs to be created (e.g., based on file changes) and how to create them. A build system does not compile, link, package, etc. applications directly, but instead directs separate compilers, linkers, and packagers to do that work.

Gradle, as used by default in Android Studio Arctic Fox, uses a domain-specific language (DSL) built on top of Groovy to accomplish these tasks.

What is Groovy?

There are many programming languages that are designed to run on top of the Java VM. Kotlin is one of particular importance for Android developers. Groovy is another.

As with Java, Groovy supports:

Groovy also resembles Kotlin in some ways:

What Does Android Have To Do with Gradle?

Google has published the Android Gradle Plugin, which gives Gradle the ability to build Android projects. Google is also using Gradle and the Android Gradle Plugin as the build system behind Android Studio.

Hey, I Thought I Read That Gradle Used Kotlin Scripts?

There is an option, starting with Android Studio 4.0, to use Kotlin scripts for defining your Gradle builds, instead of Groovy scripts. If you see a project with build.gradle.kts files instead of build.gradle files, that project is using Kotlin Gradle scripts instead of Groovy ones.

This is likely to prove to be the long-term direction for Android. However, this book is going to focus on Groovy scripts, for a few reasons:


Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.