How to install Gradle

Gradle is a simple and yet strong build tool. It is similar to the Ant build tool. It manages the build well and also handles build dependencies. The best part of Gradle is that it is open source project. If you are thinking about installing and giving it a try, then you are at the right place. Gradle development cycle is of 4 weeks, so after every four weeks they roll out a new version of Gradle. Here, I am assuming that you are going to install Gradle on linux/Ubuntu machine.

Gradle setup steps

  1. Download Gradle from here. Gradle download comes in three different flavors.
    • Binaries, Documentation and Source code
    • Binaries only
    • Source code only

    The first one is recommended since it comes with documentation and source code. If you are not interested in documentation and source file, you can download Binaries only package. 

  2.  unzip the download file
      $unzip gradle-[version]-[type].zip
    

    here type can be all, bin, or src. It is based on type of downloaded flavor.

  3. The bin file should be in the system path, only then you can execute the Gradle command. It can be done either by executing the command given below or by editing the .bashrc to set the PATH variable.
      #modify the directory path according to the setup.
      $ export PATH=$PATH:/gradle-directory-path/gradle-directory/bin
    
  4. Now execute the following command on terminal
     $ gradle     #you will see the output below.
    
     :help
    
    Welcome to Gradle 1.1.
    
    To run a build, run gradle  ...
    To see a list of available tasks, run gradle tasks
    To see a list of command-line options, run gradle --help
    BUILD SUCCESSFUL
    Total time: 2.607 secs
    

    If you don’t the the above print, then you need to recheck the PATH variable.

Hello wold!! in Gradle

After installing Gradle, let’s try a simple Gradle file. Create a file named build.gradle and copy the code given below in this file.

task("hello"){
  println "Hello world!!"
}

The way we define targets in Makefile, similarly we define tasks in gradle script. In the above code we have created a simple task called hello which prints Hello world!!.
For executing this script, just execute the command below on the terminal in the same directory.

$ gradle hello   #you will get similar out put as shown below.

Hello world!!
:hello UP-TO-DATE

BUILD SUCCESSFUL

Gradle command looks for build.gradle file in the current directory and executes the specified task(s) similar to make command which looks for Makefile in the current directory and executes the specified target(s).

Reference: how to install gradle from our JCG partner Rakesh Cusat at the Code4Reference blog.

Related Whitepaper:

Functional Programming in Java: Harnessing the Power of Java 8 Lambda Expressions

Get ready to program in a whole new way!

Functional Programming in Java will help you quickly get on top of the new, essential Java 8 language features and the functional style that will change and improve your code. This short, targeted book will help you make the paradigm shift from the old imperative way to a less error-prone, more elegant, and concise coding style that’s also a breeze to parallelize. You’ll explore the syntax and semantics of lambda expressions, method and constructor references, and functional interfaces. You’ll design and write applications better using the new standards in Java 8 and the JDK.

Get it Now!  

One Response to "How to install Gradle"

  1. MintMan says:

    Thanks for this, I was so confused about something so basic. Very clear, and worked right away!

Leave a Reply


four + = 7



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.

Sign up for our Newsletter

15,153 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

  • Fresh trends
  • Cases and examples
  • Research and insights
  • Two complimentary e-books
Get tutored by the Geeks! JCG Academy is a fact... Join Now
Hello. Add your message here.