Category Archives: Gradle

Gradle Build Automation – Part 4

Understanding Gradle Processes.

How Gradle Executes Scripts

  1. Gradle reads the script file.
  2. Creates a Project Object and configure it (set up data).
  3. Finally set of tasks to be executed is determined and executed.

We can project object in Gradle script with the variable name project. We can set the project description like this,

setDescription(“My First Gradle Script”)   or    project.setDescription(“My First Gradle Script”)

Gradle tasks

Lets make it simple. Project ( has one or more tasks ), Task is made up of actions.

doFirst {

println ‘Running first’


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


Eclipse Integration with Groovy is very simple, here we go!

  1. Using Eclipse Install New Software, install Groovy-Eclipse plug-in from IDE section.
  2. Create new project from eclipse and select new Groovy Project
  3. Create a new Groovy Class with the following code
  4. package com.vogella.groovy.first
    class FirstGroovy {
      static void main(def args){
        def mylist=[1,2,"Lars","4"]
        mylist.each{ println it }
  5. Right-click the Groovy class, and select Run AsGroovy Script from the context menu.


Gradle – Build Automation – Part 1

Well Gradle time guys!

I have started to blog down things, i come across developement, first it will help others to troubleshoot and find improvement in my engineering and second to start sharing with community from whom i have learned a lot!

We will be discussing installation of Gradle in this post on Windows 7. Following steps will help in setting up Gradle in your local machine.


  1. Download Gradle from Gradle Website
  2. Extract the Zip File to some folder , i m using Drive D:\GradleWare\
  3. Need to Setup Environment Variable , Add GRADLE_HOME with value  D:\GradleWare and add Gradle bin to PATH environment variable i.e PATH value  = …..;D:\GradleWare\bin
  4. Open Command Prompt and Type gradle -v
Gradle 2.2.1
Build time: 2014-11-24 09:45:35 UTC
Build number: none
Revision: 6fcb59c06f43a4e6b1bcb401f7686a8601a1fb4a
Groovy: 2.3.6
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.7.0_45 (Oracle Corporation 24.45-b08)
OS: Windows 7 6.1 amd64