Building Hadoop Application Using Gradle

In our previous blogs, we have seen how to build Hadoop applications using Maven and SBT. Now in this blog, we will show a demo on building Hadoop application using Gradle. But before we begin, let us see what is Gradle.

Gradle is an open source build automation system that builds upon the concepts of Apache Ant and Apache Maven and introduces a Groovy-based domain-specific language (DSL) instead of the XML form used by Apache Maven of declaring the project configuration.

100% Free Course On Big Data Essentials

Subscribe to our blog and get access to this course ABSOLUTELY FREE.

Building Hadoop Application Using Gradle

Installing Gradle in Linux

For Debian based systems like Ubuntu, use the below command to install Gradle.

Sudo apt-get install Gradle

Installing Gradle in Eclipse

Gradle can also be integrated with Eclipse. Let us now see the procedure to integrate Gradle with Eclipse.

If you are using Eclipse Neon, then click on Help–> Install New Software–> Here give the below link.

Now we have created one file called Hadoop_app_gradle and inside src/main/java we have pasted the code of Hadoop word count program.

Inside the root directory i.e., Hadoop_app_gradle you need to create one more file called build.gradle. Here, you need to provide all the specifications and library dependencies of your project. Here are our specifications of Gradle build.

Above are the specifications of our Gradle file. Now we will build the Gradle project using the command Gradle build. This command will compile your code and will build a jar file automatically.

After successful compilation and building of the jar, you can see a success message and in the project_root_folder/build/libs directory, you can see the jar file.

To make this project eclipse ready, you need to use the command sbt eclipse to build the project and classpath that are required for eclipse. You can see the same in the below screen shot.

Now your project is ready to import into eclipse. For importing the project into eclipse, follow the below procedure.

Open Eclipse –> Click on File–> Click on Import–> Click on General –> Click on Existing Projects into Workspace — >Select root directory–>Click on Browse–>Select the project file which you have created–>Click on ok

In the next screen, select all the projects present and click on Finish.

Now you can browse this project as a normal eclipse project.

Let us run the jar file which we have built using Gradle with the Hadoop jar command. Here is the command we have used to run the jar file.