Gradle – Installation on windows and Unix

Gradle is another build automation tool like other tools Ant, Maven etc., Gradle can automate the building, testing, publishing, deployment and more of software packages or other types of projects such as generated static websites, generated documentation or indeed anything else.

Gradle combines the power and flexibility of Ant with the dependency management and conventions of Maven into a more effective way to build. Powered by a Groovy DSL and packed with innovation, Gradle provides a declarative way to describe all kinds of builds through sensible defaults. Gradle is quickly becoming the build system of choice for many open source projects, leading edge enterprises and legacy automation challenges.

Gradle’s build scripts are written in Groovy, not XML. But unlike other approaches this is not for simply exposing the raw scripting power of a dynamic language. That would just lead to a very difficult to maintain build. The whole design of Gradle is oriented towards being used as a language, not as a rigid framework.

Before going to discuss installation of Gradle, it is worth to understand it’s features.

Features of Gradle

  1. Declarative builds
  2. You can structure your build.
  3. Deep API to support most of the automation challenges.
  4. Multi -module project builds
  5. Many different ways to manage dependencies.
  6. Ease of migration
  7. It’s Free and Open source

1. Install Java 1.7

Gradle requires a Java JDK to be installed. Gradle requires a JDK 1.5 or higher. Gradle ships with its own Groovy library, therefore no Groovy needs to be installed. Any existing Groovy installation is ignored by Gradle. Gradle uses whichever JDK it finds in your path (to check, use java -version). Alternatively, you can set the JAVA_HOME environment variable to point to the install directory of the desired JDK.

Install Java 1.7 from oracle and set JAVA_HOME and Path variables to point Java 1.7 installation. For more information on how to install and setup Java 1.7 on windows see here .

2. Download Gradle

You can download one of the Gradle distributions from the Gradle web site. In the current tutorial, I’m using Gradle version 2.1, but you can select latest version at the time of your installation.

http://www.gradle.org/downloads

3. Gradle Installation

The Gradle distribution comes packaged as a ZIP. The full distribution contains:

  1. The Gradle binaries.
  2. The user guide (HTML and PDF).
  3. The DSL reference guide.
  4. The API documentation (Javadoc and Groovydoc).
  5. Extensive samples, including the examples referenced in the user guide, along with some complete and more complex builds you can use the starting point for your own build.
  6. The binary sources. This is for reference only. If you want to build Gradle you need to download the source distribution or checkout the sources from the source repository. See the Gradle web site for details.

Unzipping  / Unpacking on Windows

I have downloaded Gradle version 2.1 which is gradle-2.1-all.zip   Extract zip folder to let say C:\gradle-2.1  Just folders and files, that’s all no installation required.

Unzipping  / Unpacking on Unix

You need a GNU compatible tool to unzip Gradle, if you want the file permissions to be properly set. We mention this as some zip front ends for Mac OS X don’t restore the file permissions properly.

4. Environment Variables

  1. JAVA_HOME
  2. Path
  3. GRADLE_HOME
  4. GRADLE_OPTS

Set JAVA_HOME and Path variables to appropriate Java installation as described in this post.

Add new  GRADLE_HOME   to point Gradle 2.1 installation folder.

Windows: GRADLE_HOME:C:\gradle-2.1  Unix: export GRADLE_HOME=/usr/local/gradle-2.1  if gradle-2.1 is extracted to /usr/local/

For running Gradle, add GRADLE_HOME/bin to your PATH  environment variable. Usually, this is sufficient to run Gradle. Update Path  variable to point Gradle bin folder, so that you can use Gradle commands from command-line.

Windows: Path:GRADLE_HOME\bin;%Path%;  or Path:C:\gradle-2.1\bin;%Path%; Unix: export PATH=$PATH:GRADLE_HOME/bin;

If you are using Gradle in development or production for a large scale project, you may run out of memory. Set GRADLE_OPTS  to specify memory settings and other file encoding settings.

GRADLE_OPTS:-Xms256m-Xmx512m 

5. JVM Options

JVM options for running Gradle can be set via environment variables. You can use GRADLE_OPTS  or JAVA_OPTS . Those variables can be used together. JAVA_OPTS is by convention an environment variable shared by many Java applications. A typical use case would be to set the HTTP proxy in JAVA_OPTS and the memory options in GRADLE_OPTS. Those variables can also be set at the beginning of the gradle or gradlew script.

6. Verification of your Gradle 2.1 installation

Open command prompt and issue the command gradle -v  The output shows gradle version and also local environment configuration (groovy and jvm version, etc.).

Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
C:\Users\Umashankar>gradle -v
------------------------------------------------------------
Gradle 2.1
------------------------------------------------------------

Build time:   2014-09-08 10:40:39 UTC
Build number: none
Revision:     e6cf70745ac11fa943e19294d19a2c527a669a53

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 x86

Thant’s it! you are now ready to build projects using Gradle.

Leave a Comment