Gradle, install this automation tool for Java projects

about gradle

In the next article we are going to take a look at Gradle. This is one general purpose build tool which is mainly used in Java projects. Combine the best features of Ant and Maven. Unlike its predecessors, which use XML for scripting, Gradle uses Groovy. This is a dynamic, object-oriented programming language for the Java platform with which to define the project and create scripts.

In this post we will see how install Gradle on Ubuntu 18.10. The same instructions apply to other versions of Ubuntu and any Ubuntu-based distribution, including Linux Mint and Elementary OS.

General features of Gradle

  • Gradle is an automation tool for compilation. It is open source and focuses on the flexibility and performance. Gradle build scripts are written using a Groovy or Kotlin DSL.
  • Es highly customizable. Gradle is modeled in a way that makes it customizable and extensible.
  • Gradle completes tasks quickly. Reuse the results of previous runs, processing only the inputs that have changed and executing tasks in parallel. Thus doing their tasks very quickly.
  • This is the official build tool for Android. It comes with support for many popular languages ​​and technologies.

Install Gradle on Ubuntu

In the following example we will see step-by-step instructions on how install latest version of Gradle on Ubuntu 18.10. For this we are going to download the latest version from its official website.

Before starting the installation, we will have to make sure that in our operating system we have OpenJDK installed. If not, you can follow the instructions below.

Install OpenJDK

gradle requires Java JDK or JRE version 7 or higher so that we can install and work with it properly. In this example I am going to use OpenJDK 8.

Installing Java is pretty simple on Ubuntu. We will start, first of all, by updating the package index by typing in a terminal (Ctrl + Alt + T):

sudo apt update

We continue installing the OpenJDK package typing in the same terminal:

sudo apt install openjdk-8-jdk

Once the installation is finished, we can verify it by executing the following command. This is going to print java version:

java -version

If everything has been correct, we should see an output similar or equal to this:

java gradle version

Download Gradle

At the time of writing, the latest version of Gradle is 4.10.2. Before proceeding to the next step, it is always interesting consult the releases page by Gradle to see if a newer version is available.

download gradle package

Once we are sure of what we have to download, we can go on to get the zip file. Let's go to download the Binary-only file In the address book / Tmp using the following wget command:

wget https://services.gradle.org/distributions/gradle-4.10.2-bin.zip -P /tmp

Once the download is complete, we are going to extract the zip file in the / opt / gradle directory:

sudo unzip -d /opt/gradle /tmp/gradle-*.zip

We will be able view gradle files unzipped listing the directory /opt/gradle/gradle-4.10.2:

gradler files

ls /opt/gradle/gradle-4.10.2

Setting the environment variable

We continue by setting the PATH environment variable to include Gradle's bin directory. To do so, we are going to open our favorite text editor and we will create a new file called gradle.sh inside the directory /etc/profile.d/.

Paste the following configuration into the file:

Gradle environment variable setting

export GRADLE_HOME=/opt/gradle/gradle-4.10.2
export PATH=${GRADLE_HOME}/bin:${PATH}

Then save and close the file. The next step to follow will be make the script executable. We will do this by typing the following command in the terminal (Ctrl + Alt + T):

sudo chmod +x /etc/profile.d/gradle.sh

Now we only have to go back load environment variables using the following command in the same terminal:

source /etc/profile.d/gradle.sh

Verify the Gradle installation

To verify that Gradle is installed correctly, we will use the following command. This will show us the installed version:

Gradle installation finished

gradle -v

If we see something like the previous screenshot, it will mean that the latest version of Gradle is already installed on our Ubuntu system.

With all this, we will have successfully installed Gradle on Ubuntu 18.10. Now we can visit the Official Documentation page and learn how to use Gradle.


Be the first to comment

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.