A general- ‐purpose build automation tool. It can automate building, testing, deployment, publishing, generate documentation etc.
Designed to take advantage of convention over configuration.
Combines the power and flexibility of Ant with the dependency management and
conventions of Maven into a more effective way to build.
2. Agenda
2
• What and Why?
• Key features of Gradle
• Project and tasks
• Using java/groovy/war/jetty plugins
• Manage dependency
• Working with multi-‐module project
3. What is Gradle?
3
• A general-‐purpose build automation tool. It can automate
• building
• testing
• deployment
• publishing
• generate static websites
• generate documentation
• indeed anything else
• Designed to take advantage of convention over configuration.
• Combines the power and flexibility of Ant with the dependency management and
conventions of Maven into a more effective way to build.
8. Installation
$ gvm install gradle
$ gradle - v
$ gradle init
$ gradle tasks
Using gvm: Ubuntu
Access gradle documentation from local file system
{USER_HOME}/.gvm/gradle/current/docs/userguide/userguide.pdf
In Windows
http://bryanlor.com/blo
g/gradle-tutorial-how-i
nstall-gradle-windows
Install
Java
9. Gradle project
9
• It does not necessarily represent a thing to be built.
• It might represent a
• library jar
• Web-app
• distribution zip assembled from the JARs produced by other projects.
• thing to be done : deploy to staging server
10. Gradle Tasks
1
0
• An atomic piece of work that a build performs.
• compile classes
• create jar
• generate java doc
• publish some archive to a repository
• Each project is made up of one or more tasks
11. Gradle Tasks
1
0
task compile {
doLast {
println 'compiling source'
}
}
task compileTest(dependsOn: compile) {
doLast {
println 'compiling unit tests'
}
}
task test(dependsOn: [compile, compileTest]) {
doLast {
println 'running unit tests'
}
}
task dist(dependsOn: [compile, test]) {
doLast {
println 'building the distribution'
}
}
> gradle dist test
:compile
compiling source
:compileTest
compiling unit tests
:test
running unit tests
:dist
building the distribution
BUILD SUCCESSFUL
Total time: 1 secs
> gradle dist -x test
:compile
compiling source
:dist
building the distribution
BUILD SUCCESSFUL
Total time: 1 secs
12. Using plugins
1
2
• Gradle core intentionally provides very little for automation.
• All of the useful features are added by plugins. e.g. java compile.
• Gradle plugins
• add new tasks (e.g. JavaCompile)
• add domain objects (e.g. SourceSet)
• add conventions (e.g. Java source is located at src/main/java)
• extends core objects and objects from other plugins
• Plugin portal : http://plugins.gradle.org/
13. Applying plugins
1
3
Script plugins
Binary plugins
Using plugins DSL
//from a script on the local filesystem or at a remote location.
apply from: 'other.gradle'
//Applying a binary plugin
apply plugin: 'java'
//Version is optional
plugins {
id "com.jfrog.bintray" version "0.4.1"
}
plugins {
id 'java'
}