Gradle – Build Automation – Part 3

We will understand some out of box gradle jargons.

Create a file build.gradle (file name should be build.gradle)

task helloWorld << {
    println 'Welcome to Gradle First Project'

From command prompt , move to the folder where build.gradle file resides and type following command in command prompt

gradle helloWorld

Welcome to Gradle First Project


Total time : 3.593 secs

// Gradle execution is displaying time and success message because as gradle runs in JVM, there fore it must be started each time we run a Gradle Build.

gradle -q helloWorld

Welcome to Gradle First Project

// using command line options of gradle will suppress messages except error messages.


We build a simple task using Gradle, although Gradle has several built-in tasks we can execute, which can be displayed using

gradle -q tasks  // displays task of our project

gradle -q dependencies  // displays project dependancies

gradle -q projects  // display sub-projects (if any) for root project


Task name abbreviation

A fantastic feature of Gradle , which helps us to shortcut names to our tasks  i.e, in our build.gradle file we have following tasks

Task #01 deleteOldDataIfAny
Task #02 getDataFromSvn
Task #03 compileData
Task #04 publishWAR

Instead of writing complete task name in gradle command line options, we can  use

gradle deleteOl
gradle dODI
gradle compileD
gradle cD


Executing Multiple Tasks

gradle deleteOldDataIfAny  getDataFromSvn //executing multiple tasks

Gradle GUI

gradle –gui //enable GUI mode for Gradle

Running Gradle Tasks without Execution

gradle –dry-run taskName //enable GUI mode for Gradle

Executing Gradle From Different Folders

D: Parent_Folder

|— Folder A

|— Folder B

|— GradleTask_Folder

|————|—————- build.gradle

Suppose we are standing at D:\Parent_Folder>, to execute build.gradle in GradleTask Folder we need to

gradle –project-dir GradleTask_Folder taskName  //executing taskName from build.gradle inside GradleTask_Folder.


Gradle Daemon

We know that Gradle runs on JVM and each time we invoke gradle command ( a new java virutal machine ) is started.

Gradle classes and libraries are loaded, and build is executed.

We can reduce build time , if we dont have to load JVM, Gradle Classes, libraries each time we execute a build.

gradle –daemon    //starts a new Java process that will have all classes , libraries already loaded and then build is executed.

After above command if we execute gradle command again , only Build is executed


Tagged: , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: