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.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

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


× 4 = four



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
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.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close