You are on page 1of 4

Page 1 Gradle- Hands on Lab

Gradle - Installation and execution of Build

Installation

Pre-requisites

Java is required for Gradle installation

Install Java
#verify the installation
java -version

Installing Gradle manually

Step 1. Download the latest Gradle distribution


The current Gradle release is version 6.7, released on 14 Oct 2020. The distribution zip file comes in two flavors:
• Binary-only
• Complete, with docs and sources
If in doubt, choose the binary-only version and browse docs and sources online.

Step 2. Unpack the distribution


Page 2 Gradle- Hands on Lab
Linux & MacOS users
Unzip the distribution zip file in the directory of your choosing, e.g.:
$ mkdir /opt/gradle
$ unzip -d /opt/gradle gradle-6.7-bin.zip
$ ls /opt/gradle/gradle-6.7
LICENSE NOTICE bin getting-started.html init.d lib media

Microsoft Windows users


Create a new directory C:\Gradle with File Explorer.
Open a second File Explorer window and go to the directory where the Gradle distribution was downloaded. Double-click the ZIP
archive to expose the content. Drag the content folder gradle-6.7 to your newly created C:\Gradle folder.
Alternatively you can unpack the Gradle distribution ZIP into C:\Gradle using an archiver tool of your choice.

Step 3. Configure your system environment

Linux & MacOS users


Configure your PATH environment variable to include the bin directory of the unzipped distribution, e.g.:
$ export PATH=$PATH:/opt/gradle/gradle-6.7/bin

Microsoft Windows users


In File Explorer right-click on the This PC (or Computer) icon, then click Properties -> Advanced System Settings -> Environmental
Variables.
Under System Variables select Path, then click Edit. Add an entry for C:\Gradle\gradle-6.7\bin. Click OK to save.
Page 3 Gradle- Hands on Lab

Step 4. Verify your installation


Open a console (or a Windows command prompt) and run gradle -v to run gradle and display the version, e.g.:
$ gradle -v

------------------------------------------------------------
Gradle 6.7
——————————————————————————————

Task is the “key” in Gradle. All actions can be defined as tasks

Note: While defining tasks ensure to not use the inbuilt tasks of Gradle

Common Gradle Commands

Create build.gradle file


Include a plugin for “java”

vi build.gradle

apply plugin: “java”

task demo {
Println “Demo”
}
Page 4 Gradle- Hands on Lab

Execute with above gradle build configuration file by running the below set of commands :

gradle tasks - List the tasks in Gradle


gradle build - Perform build
gradle clean - Perform Clean up
gradle clean build - Perform Clean up and Build
gradle build —scan - Publish the build result to Gradle portal “scan.gradle.com"

You might also like