Weitere ähnliche Inhalte Ähnlich wie The world of gradle - an introduction for developers (20) Mehr von Tricode (part of Dept) (20) Kürzlich hochgeladen (20) The world of gradle - an introduction for developers1. The world of Gradle
Tricode Slide Share
Februari 2014
Tricode BV
De Schutterij 12 -18
3905 PL Veenendaal
The Netherlands
tel: 0318 - 559210
fax: 0318 - 650909
www.tricode.nl
info@tricode.nl
3. Why create Gradle?
What happened since Ant (2000) and Maven (2003):
● Agile Manifesto
● Continues Development
● Continues Integration
● Continues Deployment
Gradle adapts these innovation in its building tool
4. Why use Gradle? (2)
“Gradle combines the power and flexibility of Ant
with the dependency management and conventions
of Maven into a more effective way to build.”
6. Gradle vs. Maven
Maven
<!-- The smallest possible Maven POM.xml -->
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.tricode.academy.samples</groupId>
<artifactId>sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
</project>
Gradle
apply plugin: 'java'
7. Maven vs. Gradle
build
|── classes
|
└── main
|
└── Main.class
|── dependency-cache
|── libs
|
└── maven-gradle-comparison-simple.jar
|── reports
|
└── tests
|
├── css3-pie-1.0beta3.htc
|
├── index.html
|
├── report.js
|
└── style.css
|── test-results
|── tmp
└── jar
└── MANIFEST.MF
10. Gradle Plugin: Java
apply plugin: 'java'
Tasks:
●assemble
●build
●buildDependencies
●buildNeeded
●check
●classes
●clean
●compileJava
compileTestJava
●jar
●javadoc
●processResources
●processTestResources
●test
●testClasses
●
12. Start testing with jUnit
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
testCompile 'junit:junit:4.8.2'
}
test {
maxParallelForks = 5
forkEvery = 50
}
13. Start testing with TestNG
apply plugin: 'java'
repositories {
mavenCentral()
}
test {
useTestNG()
}
dependencies {
testCompile 'org.testng:testng:6.0.1'
}
18. doFirst & doLast (closure)
task hello << {
println 'world'
}
hello.doFirst {
print 'hello, '
}
19. doFirst & doLast (closure) (2)
task hello << {
println 'world'
}
hello.doFirst {
print 'hello, '
}
hello.doFirst {
print 'hi, '
}
20. onlyIf (closure)
task createSchema << {
println 'create database schema'
}
task loadTestData(dependsOn: createSchema) << {
println 'load test data'
}
loadTestData.onlyIf {
System.properties['load.data'] == 'true'
}
$ build loadTestData
:createSchema
create database schema
:loadTestData SKIPPED
$ gradle -Dload.data=true loadTestData
21. DefaultTask properties
task emailMe(dependsOn: compileJava) << {
if(tasks.compileJava.didWork) {
println 'SEND EMAIL ANNOUNCING SUCCESS'
}
}
task sendEmails(dependsOn: compileJava) << {
println 'send emails'
}
sendEmails.enabled = false
22. How to build Multi Projects
project
build.gradle
apply plugin: 'java'
settings.gradle
include 'api', 'service'
Dependency Management
dependencies {
compile project(':api')
}
23. How to build Multi Projects
One build file
allprojects {
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
testCompile: 'junit:junit:4.11'
}
}
project(':service'') {
dependencies {
compile project(':api')
}
}
24. How to build Multi Projects
Hybrid
allprojects {
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
testCompile: 'junit:junit:4.11'
}
}
25. Upload artifacts
apply plugin: 'java'
apply plugin: 'maven'
group = 'com.gradleware.samples'
uploadArchives {
repositories.mavenDeployer {
repository(url: "file:///mytemprepo/")
}
}
26. Want to know more?
We suggest to read:
Building and Testing with Gradle
Tim Bergland
ISBN-10: 144930463X
ISBN-13: 978-1449304638
27. Thank you for watching this slide share
Follow us on:
tricode.nl
facebook.com/tricode
linkedin.com/company/tricode
slideshare.net/tricode
twitter.com/tricode