Build Automation Tools: Gradle

Jessica Lu
Strategio
Published in
3 min readSep 16, 2022
Source

What is Build Automation?

Build automation tools are heavily relied upon in software development to achieve the continuous integration aspect of DevOps by saving developers the time they would have spent doing these tasks manually. But what does it mean?

Build automation refers to the automation of tasks necessary to create, compile, execute and test programs. This is all then wrapped up and sent back into a centralized repository for other developers to share.

A predecessor of build automation tools is the makefiles commonly found in school projects. Makefiles contain instructions on what part of the code needs to be compiled and tested through a series of shell commands and dependencies.

What is Gradle?

One of the more widely used build automation tools is Gradle which is used for Java projects with multi-project builds in mind. It can be written in two different Domain Specific Languages, Groovy and Kotlin, which are more powerful and versatile than other tools like Maven. In addition, because its build script is a programming language, plugins are easier to apply in Gradle.

Once a build has been defined, Gradle models itself with acyclic graphs listing each task and edges illustrating dependencies when run. The user can define tasks to run specific instructions, including built-in ones such as running JUnit tests.

Creating a task

Creating your own Gradle task is quite simple.

In your project folder go to the build.gradle file which should look something like the image below:

As you can see, line 16 already contains an example of a built-in task called test that would run the JUnit tests for this project.

Add a new task called hello to print out hello to the console:

task hello {
doLast {
println("Hello!")
}
}

Call the task using gradle task-name. It is important to note that the word that comes after gradle is always assumed to be a task name so it would be incorrect to have used gradle task hello.

How do customers use Gradle?

SoundCloud is an online audio distribution platform that enables users to upload and promote audio bites and music. They have been using the Gradle remote build cache to create a more efficient delegation of time for developers on their team.

Similar to how a cache is used to find hits in a computer’s memory, the Gradle remote build cache is used to check if there are any “hits” between build versions. If there is a “hit,” then it can be reused for the following round of development saving developers the time of re-building something unnecessary.

However, SoundCloud acknowledged that blindly using the cache was not always helpful. For example, there were cases in which they would use the cache on a large set, and there would end up being no hits causing the expenditure to be more costly than if they had gone ahead without using it. Thus, it was important for them to remember how the tasks and builds work and use other tools to analyze task input differences before using the cache to make it a more efficient tool for their developers.

That was a brief overview of Gradle and its uses in Enterprise! Thank you for reading and let me know if there are any questions.

--

--