the world of gradle - an introduction for developers

Post on 26-Jan-2015

109 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

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

Tricode BVDe Schutterij 12 -183905 PL Veenendaal

The Netherlands

tel: 0318 - 559210 fax: 0318 - 650909

www.tricode.nlinfo@tricode.nl

The world of Gradle

Tricode Slide ShareFebruari 2014

“Gradle is build automation evolved”

What is Gradle?

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

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

Why use Gradle?

Imperative Declarative

Ant MavenGradle

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

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

Gradle Tasks

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

build.gradle

run

gradle -q helloWorld

output

hello, world

Available Gradle pluginsLanguage 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●compileJava

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

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

}

Start testing with jUnitapply plugin: 'java'

repositories {mavenCentral()

}

dependencies {testCompile 'junit:junit:4.8.2'

}

test {maxParallelForks = 5forkEvery = 50

}

Start testing with TestNG

apply plugin: 'java'

repositories {mavenCentral()

}test {

useTestNG()}

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

}

Testing

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

}

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

}

Gradle Tasks

task hello << {print 'hello, '

}

hello << {println 'world'

}

$ gradle -q hellohello, 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 'hi, '

}

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

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

How to build Multi Projects project

include 'api', 'service'

apply plugin: 'java'

build.gradle

settings.gradle

dependencies {compile project(':api')

}

Dependency Management

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

}

How to build Multi Projects Hybrid

allprojects {apply plugin: 'java'

repositories {mavenCentral()

}

dependencies {testCompile: 'junit:junit:4.11'

}}

Upload artifacts

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

group = 'com.gradleware.samples'

uploadArchives {repositories.mavenDeployer {

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

}

Want to know more?

We suggest to read:Building and Testing with GradleTim Bergland

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

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

Thank you for watching this slide share

top related