Templates by BIGtheme NET

Gradle Hello World in Java Using eclipse

In this article, I will show How to configure Graddle in eclipse IDE.
How to write simple hello world java program using Graddle.
The Gradle java project folder structure. How to add new java source and test classes.
How to run and build the project with Graddle.

Tools Used :

1) eclipse version Luna 4.4.1.
2) Graddle 2.11
3) JDK 1.8

Simple Steps to be followed,

1) Install Graddle plugin into eclipse.

2) Create a simple Graddle project.

3) Graddle Project Structure.

4) How to Run Graddle tasks.

5) Demo.

1) Install Graddle plugin into eclipse :

Go to Help -> Install New Software in eclipse and provide,
gradle – http://dist.springsource.com/release/TOOLS/update/e4.4/

1_Graddle Hello World in Java Using eclipse

Select required or Select All and Click next button.

2) Create a simple Graddle project :

New -> Others .

1.1_Graddle Hello World in Java Using eclipse

Graddle, under select Gradle project.

1.2_Graddle Hello World in Java Using eclipse

Click on Next button,

1.3_Graddle Hello World in Java Using eclipse

Provide the project name “Hello World” and click on Next button.

1.4_Graddle Hello World in Java Using eclipse

Click and browse the Gradle home,

1.5_Graddle Hello World in Java Using eclipse

The Graddle project is created.

3) Graddle Project Structure :

The src/ main/ java is the folder where we can have all our java sources.
The src/ test/ java is the folder where we can have all our java sources test classes.

3_Graddle Hello World in Java Using eclipse

I have added only one class HelloWorld.java as java source class.

HelloWorld.java

package com.devjavasource.graddle;

public class HelloWorld {
	String printString(){
		return "Hello World";
	}
}

Added Test class for HelloWorld.java class is TestHelloWorld.java

TestHelloWorld.java

package com.devjavasource.graddle;

import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class TestHelloWorld {
	@Test public void testHelloWorld() {
		HelloWorld helloWorld = new HelloWorld();
        assertEquals("Hello World", helloWorld.printString());
    }
}

4) How to Run Graddle tasks :

Graddle is offering given tasks as default. We can run these tasks just by right click on task and run.

4_Graddle Hello World in Java Using eclipse

5) Demo :

Right click on task test and click on Run Graddle Task.

5_Graddle Hello World in Java Using eclipse

We can see the Graddle Executions and results.

6_Graddle Hello World in Java Using eclipse

Out Put :

Gradle Tasks: test
Working Directory: C:\Venkat_06012014\Blog\Gradle\workspace\HelloWorld
Gradle User Home: C:\Users\nallave\.gradle
Gradle Distribution: Gradle wrapper from target build
Gradle Version: 2.6
Java Home: C:\Program Files\Java\jdk1.8.0_65
JVM Arguments: None
Program Arguments: None

:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE

BUILD SUCCESSFUL

Total time: 0.142 secs

You can download complete project, Here

HelloWorld

*** Venkat – Happy learning ****