Introducing Gradle
Gradle is a build system with many improvements over Ant and Maven. In this post I will go through an Hello World example on how I set up gradle on OSX and work along with eclipse. With few changes you can adapt this mini-guide on Windows and Linux.
I installed gradle binary only distribution version 2.3 on Oracle JDK 7.
The only prerequisite to install gradle is to have a working Java 6 or higher JDK or JRE, to verify use java -version on a terminal.
- Download the latest binaries from here
- unpack into a folder with the unzip command
for example I unzipped into the following (see path after the “pwd” command):
- update your path to add bin folder inside your environment adding this line to your “.bash_profile” in your home folder (I use “vi” editor in the example below):
Append the following export command:
Save and close the file. To apply changes immedialty enter:
- Verify your installation with “gradle tasks” command:
Now that you have a working gradle setup, you can download my github project and try to execute some gradle commands on it like the following:
1
2
3
4
# build to download libraries into your local repository
gradle build
# update eclipse project to reflect new changes about the Java build path
gradle eclipse
build.gradle explanation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'
mainClassName = 'hello.HelloWorld'
// tell gradle the file name for jar task
jar {
baseName = 'hello-gradle'
version = '1.0.0'
}
// The repositories block indicates that the build should resolve its dependencies from the Maven Central repository
repositories {
mavenCentral()
}
// project dependencies, when you update dependencies always do a build and eclipse task to regenerate eclipse project with new dependencies
dependencies {
compile "joda-time:joda-time:2.7"
}
// gradle standalone task (useful if you do not have gradle installed and download the project from github, generate executable for Windows/Unix to download automagically gradle)
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
This is my Blog Access Memory post, to go deeper have a look at the full tutorial reference below.
Dino.
References
http://www.cyberciti.biz/faq/appleosx-bash-unix-change-set-path-environment-variable/