Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb...

75
Hans Dockter CEO, Gradleware Founder Gradle [email protected] Rocking the Gradle! Thursday, August 16, 12

Transcript of Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb...

Page 1: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Hans DockterCEO, GradlewareFounder [email protected]

Rocking the Gradle!

Thursday, August 16, 12

Page 2: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

What you will learn‣ Declarativeness

‣ Extensibility

‣ Performance Features

‣ Build Integration

‣ Build Migration

‣ Testing

‣ Discoverability

‣ Multiproject Builds

‣ Eclipse Integration

‣ Gradle Bootstrap Install

Thursday, August 16, 12

Page 3: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Intro

Thursday, August 16, 12

Page 4: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

What is Gradle?

‣ A general purpose build system

‣ Groovy DSL with a Java core.

‣ Provides build-in support for Java, Groovy, Scala, Web, OSGi, EAR, C/C++ and many more types. 

‣ Exciting solutions for many of the big pain points you often have with current build systems. – Maintainability– Performance– Usability– Extendability– Standardization

Thursday, August 16, 12

Page 5: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Gradle Project Background

‣ Very active community (forum, patches, issues)

‣ Apache v2 license.

‣ Excellent user’s guide (300 pages) + many samples

‣ Excellent DSL reference

‣ Frequent releases, multiple commits per day

‣ Quality is king: ‣ 6000 unit tests, 1000 integration test

‣ Healthy codebase

‣ low defect rate

‣ Some Committers and Gradleware Employees:‣ Szczepan Faber (Mr. Mockito)

‣ Peter Niederwieser (Mr. Spock)

‣ Luke Daley (Grails committer and Geb Founder)

‣ Daz DeBoer (Original contributor to Selenium and Ant)Thursday, August 16, 12

Page 6: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Thursday, August 16, 12

Page 7: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Community Portal

‣ Forum: forums.gradle.org

‣ Keep up to date: This Week in Gradle

‣ Roadmap: gradle.org/roadmap

Thursday, August 16, 12

Page 8: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Training

25.  –  27.  Sep.  2012  Frankfurt23.  –  25.  Okt.  2012  London

Sie  erhalten  einen  Raba$  von  20%  auf  die  Teilnehmergebühr,  wenn  Sie  sich  mit  dem  JFS-­‐Code  innerhalb  der  nächsten  30-­‐Tage  online  auf  www.gradleware.com/training  registrieren.    Fragen  Sie  uns  nach  dem  JFS-­‐RabaBcode!

Thursday, August 16, 12

Page 9: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Free  Webinars

A  gentle  introduc.on  to  Gradle  –  with  Tim  Berglund11.  Juli  2012  um  19:00  Uhr  (MESZ)

In-­‐depth  Gradle  1.0  Power  Features  –  with  Szczepan  Faber12.  Juli  2012  um  11:00  Uhr  (MESZ)

Administering  Gradle  in  the  Enterprise      –  with  Luke  Daley31.  Juli  2012  um  11:00  Uhr  (MESZ)

Migra.ng  and  Upgrading  with  Gradle  –  with  Szczepan  Faber9.  August  2012  um  11:00  Uhr  (MESZ)

PDT  =  Pacific  Daylight  Time  /  EDT  =  Eastern  Daylight  Time  /  CEST  =  Central  European  Summer  Time  /  BST  =  BriUsh  Summer  TimeThursday, August 16, 12

Page 10: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

O‘Reilly-­‐Buch

Das  erste  O‘Reilly-­‐Buch  bietetanschauliche  Beschreibungenund  Beispiele  zur  intensivenBeschäOigung  mit  Gradle

So  finden  Sie  das  Buch:

1. Als  E-­‐Book  auf  shop.oreilly.com

2.Als  Hardcover  im  (Online-­‐)Buchhandel

3.Zum  kostenlosen  Lesen  auf  unserer  

WebsiteThursday, August 16, 12

Page 11: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Gradle isDeclarative

Thursday, August 16, 12

Page 12: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Declarative

You specify the WHAT

Gradle figures out the HOW

Thursday, August 16, 12

Page 13: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

LabsDemo - Source Sets

Thursday, August 16, 12

Page 14: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

<project name="Foo" basedir="."> <property name="classesDir" value="build/classes/test"/> <target name="compileTests"> <javac ... destdir="${classesDir}" ... </javac> </target> <target name="test" depends="compileTests"> <junit ...> <classpath>

<pathelement path="{classesDir}"/></classpath>

</junit> </target> <target name="testJar" depends="compileTests"> <jar basedir="${classesDir}" .../> </target> </project>

An Ant Example

Thursday, August 16, 12

Page 15: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

 Gradle is

declarativewithout

being rigid

Thursday, August 16, 12

Page 16: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Extensible Build Language

vs.

Build Framework

Thursday, August 16, 12

Page 17: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

usePlugin ‘editions’

productEditions {enterprise core, plugins, powerAddonspublic core, plugins, openApi

}

Custom Language Elements

>gradle enterpriseEditionZip

>gradle publicEditionTar

Thursday, August 16, 12

Page 18: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Thursday, August 16, 12

Page 19: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Thursday, August 16, 12

Page 20: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Extensible

Thursday, August 16, 12

Page 21: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Directed Acyclic Graph (DAG)

‣ Each task to be executed is a node. 

‣ The dependsOn relations define directed edges.

‣ No cycles are allowed (acyclic)

‣ Each task is executed once and only once.

‣ Execution order is against the edge directions.

Thursday, August 16, 12

Page 22: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Expect the unexpected

‣ Custom Language Elements

‣ Deep Configuration API

‣ Deep Execution API

‣ Rich API

‣ Extendable Domain Objects

‣ Custom Tasks

‣ Custom Plugins

Thursday, August 16, 12

Page 23: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

LabsDemo - Task Rules

Thursday, August 16, 12

Page 24: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Groovy vs.XML

Thursday, August 16, 12

Page 25: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

 It’s the design, stupid!

Thursday, August 16, 12

Page 26: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Pleaseno

messybuild scripts

Thursday, August 16, 12

Page 27: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Performance

Thursday, August 16, 12

Page 28: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

LabsDemo-Excluding Tasks

Thursday, August 16, 12

Page 29: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Smart Exclusion

>gradle A -x B

Thursday, August 16, 12

Page 30: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

TaskInput/Output

Thursday, August 16, 12

Page 31: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

LabsDemo-Incremental Build

Thursday, August 16, 12

Page 32: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Should clean be required for a reliable build?

(Hint: We have the 21st century)

Thursday, August 16, 12

Page 33: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Task Input/Output

‣ You can describe:‣ Input/Output Files

‣ Input/Output Dirs

‣ Input Properties

‣ Gradle’s build-in tasks all describe their input/output.

Thursday, August 16, 12

Page 34: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Incremental Build

‣ The hashes of the input/output files are cached.

‣ The hashes for all files of the input dirs are cached.

‣ The property values are cached (serialized).

‣ Cache == Current -> Skip Task

Thursday, August 16, 12

Page 35: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

class MyTask extends DefaultTask { @InputFile File text @InputFiles FileCollection path @InputDirectory File templates @Input String mode @OutputFile File result @OutputDirectory transformedTemplates File someProp // ignored @TaskAction generate() { ... } }

Annotations

Thursday, August 16, 12

Page 36: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

ant.import 'build.xml' someAntTarget { inputs.files 'template.tm',new File('data.txt') inputs.dir 'someDir' outputs.files 'output.txt' outputs.dir 'generatedFilesDir' outputs.upToDateWhen { task -> dbDataUpToDate(task.dbUrl) } }

Input/Output API

Thursday, August 16, 12

Page 37: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Property Processing

‣ Exception if input files/dir do not exists‣ Disable validation with @Optional

‣ Output dirs are created before execution.

Thursday, August 16, 12

Page 38: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Performance

‣ Incremental Build

‣ Parallel Testing

‣ Soon: Parallel Builds, Distributed testing/builds

‣ Rich Model

Thursday, August 16, 12

Page 39: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Integration

Thursday, August 16, 12

Page 40: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Ant

Thursday, August 16, 12

Page 41: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Ant

‣ Ant is Gradle's friend not its competitor.

‣ Gradle uses Ant task's internally.

‣ You can use any Ant task from Gradle.

‣ Ant tasks are an integral part of Gradle.

‣ Gradle ships with Ant.

‣ You can import any Ant build into Gradle

Thursday, August 16, 12

Page 42: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

ant.delete dir: 'someDir' ant { ftp(server: "ftp.comp.org", userid: 'me', ...) { fileset(dir: "htdocs/manual") { include name: "**/*.html" } // high end myFileTree.addToAntBuilder(ant, 'fileset') } mkdir dir: 'someDir' }

Ant Tasks

‣ Gradle provides an instance of the Groovy AntBuilder

Thursday, August 16, 12

Page 43: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

<project>  <target name="hello" depends="intro"> <echo>Hello, from Ant</echo>  </target> </project>

Importing Ant Builds

ant.importBuild 'build.xml' hello.doFirst { println 'Here comes Ant' } task intro << { println 'Hello, from Gradle'}

>gradle helloHello, from GradleHere comes Ant[ant:echo] Hello, from Ant

Thursday, August 16, 12

Page 44: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Maven

Thursday, August 16, 12

Page 45: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

LabsDemo-Maven Import

Thursday, August 16, 12

Page 46: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Maven

‣ Retrieve/Deploy to Maven/Ivy repositories

‣ Autogeneration of pom.xml/ivy.xml

‣ Convert Maven build into build.gradle

‣ Import of Maven builds‣ Soon: Deep Import

‣ Soon: Use Gradle from Maven

Thursday, August 16, 12

Page 47: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Ecosystem‣ Deep Integration with Artifactory

‣ Nexus

‣ Jenkins/Hudson

‣ Teamcity

‣ Eclipse (via STS)

‣ Idea 11

‣ Sonar

Thursday, August 16, 12

Page 48: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Migration

Thursday, August 16, 12

Page 49: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Build Migration

‣ Mission Critical!

‣ Nightmare if the new build system can’t adapt to the existing project layout:‣ Freeze

‣ Project automation not working for a while

‣ Different branches (unreliable, hard to compare, ...)

‣ Gradle’s suppleness enables baby steps.‣ Gradle can adapt to any project layout.

‣ No separate branches

‣ Comparable --> Write tests

Thursday, August 16, 12

Page 50: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

EnterpriseDependency

Cache

Thursday, August 16, 12

Page 51: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

New Dependency Cache

‣ Metadata cache per resolver (url = id)

‣ Global checksum cache for jars

‣ Concurrency

‣ Dynamic Versions

‣ SOON: Reuse existing caches (older Gradle versions, m2, ivy)

Thursday, August 16, 12

Page 52: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Usecases

‣ Repository Change:‣ A new metadata cache is created

‣ Check for Jar‣ If not there, Exception:

‣ If checksum OK no download

‣ No inconsistencies between cache and repository.

‣ Dynamic revisions are retrieved per repository.

‣ Changing modules are retrieved per repository.

‣ Local installs don’t pollute other builds.

Thursday, August 16, 12

Page 53: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Benefits

‣ Local Cache is not hiding problems

‣ Local Cache is not creating special behaviour

‣ Better Reproducibility.

‣ Transactional

Thursday, August 16, 12

Page 54: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Testing

Thursday, August 16, 12

Page 55: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Test Task

‣ Support for JUnit and TestNG

‣ Parallel Testing

‣ Custom Fork Frequency

‣ Remote Listeners

‣ Tests auto-detected in sourceSets.test.classes

Name

Type

Input

test

Test

sourceSets.test.classesconfigurations.testRuntime

Thursday, August 16, 12

Page 56: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

test { jvmArgs: ["-Xmx512M"] include "**/tests/special/**/*Test.class" exclude "**/Old*Test.class" forkEvery = 30 maxParallelForks = guessMaxForks() } def guessMaxForks() { int processors = Runtime.runtime.availableProcessors() return Math.max(2, (int) (processors / 2)) }

Test Task Example

Disables Auto Detection

Thursday, August 16, 12

Page 57: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

test { beforeTest { descr -> // do something } afterTest { descr, result -> // do something } afterSuite { descr, result -> // do something } }

Test Task Listeners

Thursday, August 16, 12

Page 58: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

LabsDemo - Testing

Thursday, August 16, 12

Page 59: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Discoverability

Thursday, August 16, 12

Page 60: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Lifecycle Tasks

‣ The relevant tasks for a build user.

‣ Achieve a certain stage in the build lifecycle for a project.‣ clean

‣ classes

‣ test

‣ assemble

‣ check

‣ build (depends on assemble and check)

‣ Hooks for worker tasks.

Thursday, August 16, 12

Page 61: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

LabsLab 19-Discoverability

Thursday, August 16, 12

Page 62: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

MultiprojectBuilds

Thursday, August 16, 12

Page 63: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Multi-Project Builds

‣ Arbitrary Multiproject Layout

‣ Configuration Injection

‣ Project Dependencies & Partial builds

‣ Separate Config/Execution Hierarchy

Thursday, August 16, 12

Page 64: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

subprojects { apply plugin: 'java' dependencies { compile "commons-lang:commons-lang:3.1" testCompile "junit:junit:4.4" } test { jvmArgs: ['Xmx512M'] } }

Configuration Injection

‣ ultimateApp‣ api

‣ webservice

‣ shared

Thursday, August 16, 12

Page 65: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

configure(nonWebProjects()) { jar.manifest.attributes Implementor: 'Gradle-Inc' } def nonWebProjects() { subprojects.findAll {project -> !project.name.startsWith('web') } }

Filtered Injection

‣ ultimateApp‣ api

‣ webservice

‣ shared

Thursday, August 16, 12

Page 66: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

dependencies { compile "commons-lang:commons-lang:3.1", project(':shared') }

Project Dependencies

‣ ultimateApp‣ api

‣ webservice

‣ shared

First Class Citizen

Thursday, August 16, 12

Page 67: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Partial Builds

‣ ultimateApp‣ api

‣ webservice

‣ shared

>gradle build>gradle buildDependents>gradle buildNeeded

Thursday, August 16, 12

Page 68: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

There isno one-size-fits-all

project structurefor the

enterprise.

Thursday, August 16, 12

Page 69: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

 The physicalstructure of your projects should

be determined byyour

 requirements.

Thursday, August 16, 12

Page 70: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

include 'project1','project2','project2:child1'

// Everything is configurable rootProject.name = 'main' project(':project1').projectDir = '/myLocation' project(':project1').buildFileName = 'project1.gradle'

Defining a Multi Project Build

‣ settings.gradle (location defines root).

‣ root project is implicitly included

Defines a virtual hierarchy By default maps to file path <root>/project1

Default to root dir name

Default to build.gradle

Thursday, August 16, 12

Page 71: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

LabsLab 20-Multi-Project Build

Thursday, August 16, 12

Page 72: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Wrapper

Thursday, August 16, 12

Page 73: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

task wrapper(type: Wrapper) { gradleVersion = '0.6' jarPath = 'gradle' }

Wrapper Task

‣ Wrapper task generates:‣ wrapper scripts

‣ wrapper jar

‣ wrapper properties.

Thursday, August 16, 12

Page 74: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Wrapper Files

>./gradlew assemble

Thursday, August 16, 12

Page 75: Rocking the Gradle! · ‣ Peter Niederwieser (Mr. Spock) ‣ Luke Daley (Grails committer and Geb Founder) ‣ Daz DeBoer (Original contributor to Selenium and Ant) Thursday, August

Q & A

Thursday, August 16, 12