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/
Select required or Select All and Click next button.
2) Create a simple Graddle project :
New -> Others .
Graddle, under select Gradle project.
Click on Next button,
Provide the project name “Hello World” and click on Next button.
Click and browse the Gradle home,
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.
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.
5) Demo :
Right click on task test and click on Run Graddle Task.
We can see the Graddle Executions and results.
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
*** Venkat – Happy learning ****