How to install Gradle
Gradle setup steps
- 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.
- 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.
- 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
- 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.
Thanks for this, I was so confused about something so basic. Very clear, and worked right away!
Thanks for the post, simple and straightforward