the world of gradle - an introduction for developers

27
Tricode BV De Schutterij 12 -18 3905 PL Veenendaal The Netherlands tel: 0318 - 559210 fax: 0318 - 650909 www.tricode.nl [email protected] The world of Gradle Tricode Slide Share Februari 2014

Upload: tricode

Post on 26-Jan-2015

109 views

Category:

Technology


0 download

DESCRIPTION

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.

TRANSCRIPT

Page 1: The world of gradle  - an introduction for developers

Tricode BVDe Schutterij 12 -183905 PL Veenendaal

The Netherlands

tel: 0318 - 559210 fax: 0318 - 650909

[email protected]

The world of Gradle

Tricode Slide ShareFebruari 2014

Page 2: The world of gradle  - an introduction for developers

“Gradle is build automation evolved”

What is Gradle?

Page 3: The world of gradle  - an introduction for developers

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

Page 4: The world of gradle  - an introduction for developers

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.”

Page 5: The world of gradle  - an introduction for developers

Why use Gradle?

Imperative Declarative

Ant MavenGradle

Page 6: The world of gradle  - an introduction for developers

Gradle vs. 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>

Maven

apply plugin: 'java'

Gradle

Page 7: The world of gradle  - an introduction for developers

Maven vs. Gradlebuild|── 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

Page 8: The world of gradle  - an introduction for developers

Gradle Tasks

task helloWorld << { println 'hello, world'}

build.gradle

run

gradle -q helloWorld

output

hello, world

Page 9: The world of gradle  - an introduction for developers

Available Gradle pluginsLanguage plugins:

● Java● Groovy● Scala● Antlr

Integration plugins:

● EAR● Maven● OSGI● War

Page 10: The world of gradle  - an introduction for developers

Gradle Plugin: Java

apply plugin: 'java'

Tasks:●assemble●build●buildDependencies●buildNeeded●check●classes●clean●compileJava

●compileTestJava●jar●javadoc●processResources●processTestResources●test●testClasses

Page 11: The world of gradle  - an introduction for developers

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+'

}

Page 12: The world of gradle  - an introduction for developers

Start testing with jUnitapply plugin: 'java'

repositories {mavenCentral()

}

dependencies {testCompile 'junit:junit:4.8.2'

}

test {maxParallelForks = 5forkEvery = 50

}

Page 13: The world of gradle  - an introduction for developers

Start testing with TestNG

apply plugin: 'java'

repositories {mavenCentral()

}test {

useTestNG()}

dependencies {testCompile 'org.testng:testng:6.0.1'

}

Page 14: The world of gradle  - an introduction for developers

Testing

test {include '**/Test*.*'

}

task integrationTest(type: Test, dependsOn: "test") << {include '**/IntegrationTest*.*'

}

Page 15: The world of gradle  - an introduction for developers

Gradle Tasks

task hello << {print 'hello, '

}

hello << {println 'world'

}

$ gradle -q hellohello, world$

Page 16: The world of gradle  - an introduction for developers

dependsOn (Task)task hello {

print 'hello, '}

task world << {dependsOn hello

}

world << {println 'world'

}

Page 17: The world of gradle  - an introduction for developers

dependsOn (Task)

task world(dependsOn: hello) {println 'world'

}

task world {println 'world'

}

world.dependsOn hello

Page 18: The world of gradle  - an introduction for developers

doFirst & doLast (closure)

task hello << {println 'world'

}

hello.doFirst {print 'hello, '

}

Page 19: The world of gradle  - an introduction for developers

doFirst & doLast (closure) (2)

task hello << {println 'world'

}

hello.doFirst {print 'hello, '

}

hello.doFirst {print 'hi, '

}

Page 20: The world of gradle  - an introduction for developers

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

Page 21: The world of gradle  - an introduction for developers

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

Page 22: The world of gradle  - an introduction for developers

How to build Multi Projects project

include 'api', 'service'

apply plugin: 'java'

build.gradle

settings.gradle

dependencies {compile project(':api')

}

Dependency Management

Page 23: The world of gradle  - an introduction for developers

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')}

}

Page 24: The world of gradle  - an introduction for developers

How to build Multi Projects Hybrid

allprojects {apply plugin: 'java'

repositories {mavenCentral()

}

dependencies {testCompile: 'junit:junit:4.11'

}}

Page 25: The world of gradle  - an introduction for developers

Upload artifacts

apply plugin: 'java'apply plugin: 'maven'

group = 'com.gradleware.samples'

uploadArchives {repositories.mavenDeployer {

repository(url: "file:///mytemprepo/")}

}

Page 26: The world of gradle  - an introduction for developers

Want to know more?

We suggest to read:Building and Testing with GradleTim Bergland

ISBN-10: 144930463XISBN-13: 978-1449304638

Page 27: The world of gradle  - an introduction for developers

Follow us on:tricode.nlfacebook.com/tricodelinkedin.com/company/tricodeslideshare.net/tricodetwitter.com/tricode

Thank you for watching this slide share