Build automation with Gradle

As all the world knows, inside of CI/CD exists automate building. This concept is so important in DevOps because here you build your package and run automate tests (depends on the result if you are continuous or abort the next phases). I know that already there is a lot of documentation about this topic, but I will write about my concerns and opinions.

Gradle works with a few CI tools, such as Jenkins, Travis and TeamCity. Its ideal for a lot of languages, even, it can be extended by plugins (developed mainly by the community). Another feature that I like is its simplicity. All commands and use are logic, so, you no need a lot of memory in your head to remember how it works and extend its functionality.

Installation in RedHat/Centos/Fedora distributions

Firstly, you need to install a JDK, for me, OpenJDK is the best option because It is into the repositories.

sudo [yum|dnf] install unzip java-1.8.0-openjdk -y

Create the home directory for Gradle.

sudo mkdir /opt/gradlesudo chown gradleuser: /opt/gradle

Download the binary from the official site.

wget -O ~/

Uncompress the archive file.

unzip -d /opt/gradle/ gradle-6.5-bin.zipsudo vi /etc/profile.d/

Add this variable declaration in the afore-mentioned file.

export GRADLE_HOME=/opt/gradle/gradle-6.5export PATH=$PATH:$GRADLE_HOME/bin

Logout from your current session and login again.

Test your installation.

gradle --version

Gradle Basics

You have to put it into your project directory. So, once there, you must initialize with following command. Be free to put where you want, surely you will discover a better way.

gradle init

After that, some files would be generated.

The file named build.gradle must contain all tasks for build our packages. In this example as the project does not exist yet, I will not build a package, I just only show how to use this file. In the next posts I will use real examples.

I write two tasks and both just print a message.

Then, I test them.

./gradlew myTask

Second test.

./gradlew mySecondTask

Surely at one moment, we will structure our build having dependencies inside the file between tasks.

The last line of the picture is where I have declared my dependency. “mySecondTask depends on myTask”. We will see.

Now, both tasks have bee executed, just calling one of them.

As I said earlier, I will post more about Gradle and how to use it with Jenkins and so on.

Literato de sistemas, informático de letras.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store