The world of Gradle
Tricode Slide Share
Februari 2014

Tricode BV
De Schutterij 12 -18
3905 PL Veenendaal
The Netherlands
...
What is Gradle?

“Gradle is build automation evolved”
Why create Gradle?
What happened since Ant (2000) and Maven (2003):
● Agile Manifesto
● Continues Development
● Continues ...
Why use Gradle? (2)

“Gradle combines the power and flexibility of Ant
with the dependency management and conventions
of M...
Why use Gradle?

Declarative

Imperative
Ant

Gradle

Maven
Gradle vs. Maven
Maven
<!-- The smallest possible Maven POM.xml -->
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>...
Maven vs. Gradle
build
|── classes
|
└── main
|
└── Main.class
|── dependency-cache
|── libs
|
└── maven-gradle-comparison...
Gradle Tasks
build.gradle
task helloWorld << {
println 'hello, world'
}
run
gradle -q helloWorld

output
hello, world
Available Gradle plugins
Language plugins:
Java
● Groovy
● Scala
● Antlr
●

Integration plugins:

EAR
● Maven
● OSGI
● War...
Gradle Plugin: Java
apply plugin: 'java'
Tasks:
●assemble
●build
●buildDependencies
●buildNeeded
●check
●classes
●clean
●c...
Dependency Management
repositories {
mavenCentral()
mavenRepo(urls: 'http://repo.gradle.org/gradle/libs-releases-local')
}...
Start testing with jUnit
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
testCompile 'junit:junit:4.8....
Start testing with TestNG
apply plugin: 'java'
repositories {
mavenCentral()
}
test {
useTestNG()
}

dependencies {
testCo...
Testing
test {
include '**/Test*.*'
}
task integrationTest(type: Test, dependsOn: "test") << {
include '**/IntegrationTest...
Gradle Tasks
task hello << {
print 'hello, '
}
hello << {
println 'world'
}

$ gradle -q hello
hello, world
$
dependsOn (Task)
task hello {
print 'hello, '
}
task world << {
dependsOn hello
}
world << {
println 'world'
}
dependsOn (Task)
task world(dependsOn: hello) {
println 'world'
}

task world {
println 'world'
}

world.dependsOn hello
doFirst & doLast (closure)
task hello << {
println 'world'
}
hello.doFirst {
print 'hello, '
}
doFirst & doLast (closure) (2)
task hello << {
println 'world'
}
hello.doFirst {
print 'hello, '
}

hello.doFirst {
print ...
onlyIf (closure)
task createSchema << {
println 'create database schema'
}
task loadTestData(dependsOn: createSchema) << {...
DefaultTask properties
task emailMe(dependsOn: compileJava) << {
if(tasks.compileJava.didWork) {
println 'SEND EMAIL ANNOU...
How to build Multi Projects
project
build.gradle
apply plugin: 'java'
settings.gradle
include 'api', 'service'
Dependency ...
How to build Multi Projects
One build file
allprojects {
apply plugin: 'java'
repositories {
mavenCentral()
}

dependencie...
How to build Multi Projects
Hybrid
allprojects {
apply plugin: 'java'

repositories {
mavenCentral()
}
dependencies {
test...
Upload artifacts
apply plugin: 'java'
apply plugin: 'maven'

group = 'com.gradleware.samples'
uploadArchives {
repositorie...
Want to know more?
We suggest to read:
Building and Testing with Gradle
Tim Bergland
ISBN-10: 144930463X
ISBN-13: 978-1449...
Thank you for watching this slide share

Follow us on:
tricode.nl
facebook.com/tricode
linkedin.com/company/tricode
slides...
Upcoming SlideShare
Loading in...5
×

The world of gradle - an introduction for developers

1,429

Published on

This Slide Share gives you an insight in the world of Gradle. Why is it a better option than for example maven, and how to use Gradle.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,429
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
79
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

The world of gradle - an introduction for developers

  1. 1. 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
  2. 2. What is Gradle? “Gradle is build automation evolved”
  3. 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. 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.”
  5. 5. Why use Gradle? Declarative Imperative Ant Gradle Maven
  6. 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. 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
  8. 8. Gradle Tasks build.gradle task helloWorld << { println 'hello, world' } run gradle -q helloWorld output hello, world
  9. 9. Available Gradle plugins Language plugins: Java ● Groovy ● Scala ● Antlr ● Integration plugins: EAR ● Maven ● OSGI ● War ●
  10. 10. Gradle Plugin: Java apply plugin: 'java' Tasks: ●assemble ●build ●buildDependencies ●buildNeeded ●check ●classes ●clean ●compileJava compileTestJava ●jar ●javadoc ●processResources ●processTestResources ●test ●testClasses ●
  11. 11. Dependency Management repositories { mavenCentral() mavenRepo(urls: 'http://repo.gradle.org/gradle/libs-releases-local') } Dependencies { compile 'com.google.guava:guava:15.0' testCompile group: 'junit', name: 'junit', version:'4.11+' }
  12. 12. Start testing with jUnit apply plugin: 'java' repositories { mavenCentral() } dependencies { testCompile 'junit:junit:4.8.2' } test { maxParallelForks = 5 forkEvery = 50 }
  13. 13. Start testing with TestNG apply plugin: 'java' repositories { mavenCentral() } test { useTestNG() } dependencies { testCompile 'org.testng:testng:6.0.1' }
  14. 14. Testing test { include '**/Test*.*' } task integrationTest(type: Test, dependsOn: "test") << { include '**/IntegrationTest*.*' }
  15. 15. Gradle Tasks task hello << { print 'hello, ' } hello << { println 'world' } $ gradle -q hello hello, world $
  16. 16. dependsOn (Task) task hello { print 'hello, ' } task world << { dependsOn hello } world << { println 'world' }
  17. 17. dependsOn (Task) task world(dependsOn: hello) { println 'world' } task world { println 'world' } world.dependsOn hello
  18. 18. doFirst & doLast (closure) task hello << { println 'world' } hello.doFirst { print 'hello, ' }
  19. 19. doFirst & doLast (closure) (2) task hello << { println 'world' } hello.doFirst { print 'hello, ' } hello.doFirst { print 'hi, ' }
  20. 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. 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. 22. How to build Multi Projects project build.gradle apply plugin: 'java' settings.gradle include 'api', 'service' Dependency Management dependencies { compile project(':api') }
  23. 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. 24. How to build Multi Projects Hybrid allprojects { apply plugin: 'java' repositories { mavenCentral() } dependencies { testCompile: 'junit:junit:4.11' } }
  25. 25. Upload artifacts apply plugin: 'java' apply plugin: 'maven' group = 'com.gradleware.samples' uploadArchives { repositories.mavenDeployer { repository(url: "file:///mytemprepo/") } }
  26. 26. Want to know more? We suggest to read: Building and Testing with Gradle Tim Bergland ISBN-10: 144930463X ISBN-13: 978-1449304638
  27. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×