Gradle

  • Gradle is a advance build management system based on Groovy and Kotlin.
  • Supports automatic download and configuration of dependencies.
Gradle has notion of projects & tasks,
  • Gradle build consist one or more projects.
  • Each projects consists one or more tasks.(Task means a piece of work i.e Clean the folder, Compile the source code, Run the classes, SendReport after execution….so on)

About build.gradle file:

  • Every gradle project will have build.gradle file, which describes the build.
  • This file will located directly under root directory of the project.
  • build.gradle file defines the project and its tasks, user can add any type of task in this file.

Sample Task in build.gradle file for better understanding:

Before writing a sample task in gradle project, first install gradle in your machine Steps to Install here..
I installed in Mac machine by using HomeBrew command:

brew install -g gradle

Note: if you get brew command not found error by running above command, it means your machine doesn’t have HomeBrew software please install by following steps to install here

Step 1:

Create new Gradle Project in Eclipse by following this steps to create here

Step 2:

Open build.gradle file in created project and clear all the default text inside the file.

Step 3:

Add below task in your build.gradle file
    task printWelcome {
    doLast{
          println ‘Hello new user,Welcome to Gradle'
     }
   }

Step 4:

  • Open terminal, go to your gradle project root directory( Ex: cd /Users/durgaPrasad/Documents/WorkSpace/GradleProject)
  • Type "gradle printWelcome" by omitting double quotes.
Your O/p is: Hello new user, Welcome to Gradle