Gradle Eclipse Run
Gradle Eclipse Run
The goal is to create Gradle Project in Eclipse and Run main class, main method from gralde command
The details of gradle(how to install etc…) please take a look Gradle Basic
Steps
- Create project directory
- Gradle init to create gradle files
- Add gradle parameter for eclipse to build.gradle and run
- Create source directory
- Import project as gradle Project
- Use src/main/java as SourceSet from Eclipse
- Add main class under package
Create project directory
the name is mongotest
mkdir mongotest
Gradle init to create gradle files
gradle init
build.gradle, graldle.bat, gradle, etc.. we can see gradle related files under your project root
Add gradle parameter for eclipse to build.gradle and run
build.gradle
apply plugin: 'eclipse'
Run gradle eclipse command
gralde eclipse
Create source directory
mkdir -p src/main/java/com/atmarkplant/mongotest mkdir -p src/main/java/resoureces
Add sourceSets in build.gradle
build.gradle
sourceSets { main { java { srcDir 'src/main/java' } resources { srcDir 'src/main/resources' } } }
Import project as gradle Project
Import -> Gradle -> Gradle Project -> “Select directory you made”
-> Press “Build Model” button at the ride side or dialot
Select project and press finish
Use src/main/java as SourceSet from Eclipse
Right click -> Build Path -> Use as source folder
Add main class under package
package com.atmarkplant.mongotest; public class Main { public static void main(String[] args) { System.out.println("Hello!"); } }
Add Run task to build.gradle
task execute(type:JavaExec) { main = 'com.atmarkplant.mongotest.Main' classpath=sourceSets.main.runtimeClasspath }
Run execute task
gradle execute
Result
:compileJava UP-TO-DATE :processResources UP-TO-DATE :classes UP-TO-DATE :execute Hello! BUILD SUCCESSFUL