Gradle!
Tech talk - Richard Hsu
What is Gradle?
- Build automation tool
- Initial release: 2007 (8 years now!)
- Build based on Ant and Maven
Gradle Task: hello
Text
task hello << {
println 'Hello world!'
}
$ gradle hello
:hello
Hello world!
BUILD SUCCESSFUL
Total time: 2.001 secs
Gradle Task: joke
Text
task joke << {
String punchLine = " Part A!"
println "What comes before Part B?\n" + punchLine
}
$ gradle joke -q
What comes before Part B?
Part A!
Gradle Task: countUp
Text
task countUp << {
4.times { print "$it " }
}
Text
$ gradle -q countUp
0 1 2 3
Gradle:
Directed Acyclic Graph
Text
task distribution << {
println "We build the zip with version=$version"
}
task release(dependsOn: 'distribution') << {
println 'We release now'
}
gradle.taskGraph.whenReady {taskGraph ->
if (taskGraph.hasTask(release)) {
version = '1.0'
} else {
version = '1.0-SNAPSHOT'
}
}
Gradle:
Run DAG
Text
$ gradle -q distribution
We build the zip with version=1.0-SNAPSHOT
$ gradle -q release
We build the zip with version=1.0
We release now
Building Java project
apply plugin: 'java'
Build properties
project
name
path
description
projectDir
buildDir
group
version
ant
Java build file example
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile 'commons-collections:commons-collections:3.2'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
Where is the path?
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile 'commons-collections:commons-collections:3.2'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
// Use a String path to specify the source directory
compile {
source = 'src/main/java'
}
Java build file example
$ gradle build
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build
BUILD SUCCESSFUL
Total time: 2.622 secs
Supported Plugin: Language
- Java
- groovy
- scala
Supported Plugin: Language (incubating)
- assembler
- c
- cpp
- objective-c
- objective-cpp
Supported Plugin: Integration
- application (build java project on command line)
- jetty (wrap project in jetty web server)
- maven (maven-publish coming soon)
- osgi
- war
Supported Plugin: Integration
- application (build java project on command line)
- jetty (wrap project in jetty web server)
- maven
- osgi
- war
Supported Plugin: Software development
- coding standards: sonar, checkstyle, findbugs, JDepend, PMD
- IDE: eclipse, idea
- other incubating: jacoco, sonar-runner, visual-studio
- js support: gradle-grunt, node
Gradle GUI
$gradle -gui
Gradle GUI
DEMO
Gradle Continuious build
- Incubating feature
- Rebuild when src changes
- Java 7+
More Gradle info...
docs.gradle.org
Gradle in action
Questions?
G
By Richard Hsu
G
- 626