Gradle - time for a new build

of 69 /69
Gradle time for a new build Gradle time for a new build! Igor Khotin E-mail: [email protected]

description

 

Transcript of Gradle - time for a new build

Page 1: Gradle - time for a new build

Gradletime for a new build

Gradle time for a new build!

Igor KhotinE-mail: [email protected]

Page 2: Gradle - time for a new build

Background● 12+ years in the IT industry● 7+ years with Java● Flexible design promoter● Agile-junkie

Page 3: Gradle - time for a new build

What do we use?● Ant?● Maven?● Buildr?● Gradle?● ...

Page 4: Gradle - time for a new build

Any problems?● heavy builds?● long integration cycles?● build projects support?● build projects

integration?● ...

Page 5: Gradle - time for a new build
Page 6: Gradle - time for a new build

How we used to build?

Page 7: Gradle - time for a new build

punchcards...

Page 8: Gradle - time for a new build

give them to an operator

Page 9: Gradle - time for a new build

waiting for result...

Page 10: Gradle - time for a new build

take the printouts...

Page 11: Gradle - time for a new build

debug?

Page 12: Gradle - time for a new build

1977 – make

Page 13: Gradle - time for a new build

2000

Page 14: Gradle - time for a new build

Complexityant

Page 15: Gradle - time for a new build

Complexityhard to reuse

ant

Page 16: Gradle - time for a new build

Complexityhard to reuse

ant

heavy build.xml's

Page 17: Gradle - time for a new build

Complexityhard to reuse

ant

heavy build.xml's

Total Control

Page 18: Gradle - time for a new build

2001

Page 19: Gradle - time for a new build

maven

convention over configuration

Page 20: Gradle - time for a new build

maven

convention over configuration

maven central

Page 21: Gradle - time for a new build

maven

convention over configuration

dependency management

maven central

Page 22: Gradle - time for a new build

maven heavy xml's

convention over configuration

dependency management

maven central

Page 23: Gradle - time for a new build

maven heavy xml's

convention over configuration

dependency management

hard to implementcustom behavior maven central

Page 24: Gradle - time for a new build

maven heavy xml's

convention over configuration

dependency management

hard to implementcustom behavior

lost control

maven central

Page 25: Gradle - time for a new build

Gradle yesterday● Founder - Hans Dockter● 2008 – early releases● 2010 Springy Innovation Award

Page 26: Gradle - time for a new build

Gradle today● 1.0-rc2 released on April 25, 2012● Active community● Gradleware ● Apache License, Version 2.0

Page 27: Gradle - time for a new build
Page 28: Gradle - time for a new build
Page 29: Gradle - time for a new build

Gradle in the wild

Page 30: Gradle - time for a new build

Who is that Gradle?● Build integration tool● Declarative builds● Groovy-based build DSL● Build-by-convention

Page 31: Gradle - time for a new build

Who is that Gradle?● Scalable – multi-project builds● Dependency management● Ease of migration● Embeddable● Deep API

Page 32: Gradle - time for a new build

Gradle positioning

Page 33: Gradle - time for a new build

Groovy and Gradle

build.gradle

task count << { 4.times { print "$it " }}

> gradle -q count0 1 2 3

Page 34: Gradle - time for a new build

gradle task != ant task

gradle task == ant target

Page 35: Gradle - time for a new build

Build tree

Page 36: Gradle - time for a new build

Dependencies

task build << { println 'building...'}task count(dependsOn: build) << { 4.times { print "$it " }}

> gradle -q countbuilding...0 1 2 3

Page 37: Gradle - time for a new build

Lazy dependencies

task build(dependsOn: 'lazy') << { println 'building...'}task lazy << { println 'so lazy...'}

> gradle -q helloso lazy...building...

Page 38: Gradle - time for a new build

Rulesbuild.gradletasks.addRule("Pattern: ping<ID>") { String taskName -> if (taskName.startsWith("ping")) { task(taskName) << { println "Pinging: " + (taskName - 'ping') } }}task groupPing { dependsOn pingServer1, pingServer2}

> gradle -q groupPingPinging: Server1Pinging: Server2

Page 39: Gradle - time for a new build

Gradle Plugins

tasks – objects – conventions

Page 40: Gradle - time for a new build

Gradle Plugins

ear war osgi jetty maven

java scala groovy cpp antrlcheckstyle findbugs pmd sonar

Page 41: Gradle - time for a new build

Java Plugin

build.gradle

apply plugin: 'java'

> gradle build...

Page 42: Gradle - time for a new build

Java Plugin Folder Layout

src/main/java Production Java sourcesrc/main/resources Production resourcessrc/test/java Test Java sourcesrc/test/resources Test resources

just like maven...

Page 43: Gradle - time for a new build

Java Plugin Tasks Flow

Page 44: Gradle - time for a new build

Java Plugin Tasks Flow

Injectable with Groovy closures

{ println 'injecting...' }

Page 45: Gradle - time for a new build

Java build-cycle customization

apply plugin: 'java'

test.doFirst { println 'Before testing...'}test.doLast { println '...after testing.'}

Page 46: Gradle - time for a new build

● You can define rules for dependencies● Flexible repository handling● Works with Ivy and Maven repositories● Dynamic properties● and more...

Dependency management

Page 47: Gradle - time for a new build

Java & jars

apply plugin: 'java'repositories { mavenCentral()}dependencies { compile 'commons-lang:commons-lang:2.5' testCompile 'junit:junit:4.8.1'}

Page 48: Gradle - time for a new build

Ant

ant.importBuild 'build.xml'

task ant << { ant.echo(message: 'hello from Ant') ant.zip(destfile: 'archive.zip') { fileset(dir: 'src') { include(name: '**.xml') exclude(name: '**.java') } }}

Page 49: Gradle - time for a new build

Build Lifecycle

Initialization

Configuration

Execution

Page 50: Gradle - time for a new build

● Arbitrary multi-project layout● Configuration injection● Separate config/execution tree● Partial builds

Multi-project builds

Page 51: Gradle - time for a new build

Multi-project builds

include 'project1', 'project2'

root-project/ build.gradle settings.gradle project1/ build.gradle project2/ build.gradle

Page 52: Gradle - time for a new build

● To reduce the startup time● Used in STS Gradle plugin for Eclipse● Used in Intellij IDEA plugin (IDEA>10)● Used by default in Tooling API

Gradle daemon

Page 53: Gradle - time for a new build

Apache Ant vs. Apache Maven vs. Gradle

Page 54: Gradle - time for a new build

ant<?xml version="1.0"?><project name="simple" default="dist" basedir="."> <property name="src" location="src/main/java"/> <property name="srcTest" location="src/test/java"/> <property name="build" location="build"/> <property name="dist" location="${build}/lib"/> <property name="version" value="1.0-SNAPSHOT" /> <path id="classpath.compile"> <pathelement location="libs/commons-lang-2.5.jar"/> </path> <path id="classpath.test"> <pathelement location="libs/junit-4.8.2.jar"/> <pathelement location="libs/commons-lang-2.5.jar"/> <pathelement location="${srcTest}"/> <pathelement location="${build}/classes"/> <pathelement location="${build}/test-classes"/> </path>...

Page 55: Gradle - time for a new build

... <target name="init"> <mkdir dir="${build}/classes"/> <mkdir dir="${build}/test-classes"/> </target> <target name="compile" depends="init"> <javac srcdir="${src}" destdir="${build}/classes"> <classpath refid="classpath.compile"/> </javac> </target> <target name="testCompile" depends="compile"> <javac srcdir="${srcTest}" destdir="${build}/test-classes"> <classpath refid="classpath.test"/> </javac> </target>...

ant

Page 56: Gradle - time for a new build

... <target name="test" depends="testCompile"> <junit fork="yes" haltonfailure="yes"> <batchtest fork="yes"> <fileset dir="${srcTest}"> <include name="**/*Test.java"/> </fileset> </batchtest> <classpath refid="classpath.test"/> <formatter type="plain"/> </junit> </target> <target name="dist" depends="test"> <mkdir dir="${dist}"/> <jar jarfile="${dist}/coc-comparison-${version}.jar" basedir="${build}/classes"/> </target> <target name="clean"><delete dir="${build}"/></target></project>

ant

Page 57: Gradle - time for a new build

maven<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion> <groupId>grId</groupId> <artifactId>coc-comparison</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version>...

Page 58: Gradle - time for a new build

maven... <dependencies> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.5</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.1</version> <scope>test</scope> </dependency> </dependencies></project>

Page 59: Gradle - time for a new build

polyglot mavenproject { modelVersion '4.0.0' artifactId 'coc-comparison' groupId 'grId' version '1.0-SNAPSHOT'

dependencies { dependency('commons-lang:commons-lang:2.5') dependency('junit:junit:4.8.1') }

properties { 'maven.compiler.target' '1.6' 'maven.compiler.source' '1.6' }}

Page 60: Gradle - time for a new build

gradleapply plugin: 'java'

version="1.0-SNAPSHOT"group="grId"archivesBaseName="coc-comparison"

repositories { mavenCentral()}

dependencies { compile 'commons-lang:commons-lang:2.5' testCompile 'junit:junit:4.8.1'}

Page 61: Gradle - time for a new build

Gradle problems

Page 62: Gradle - time for a new build

Gradle bugs

Page 63: Gradle - time for a new build

IDE integration

Page 64: Gradle - time for a new build

market penetration

Page 65: Gradle - time for a new build

Gradle tomorrow● Release 1.0 till the end of 2012

● Deep import of maven projects● Release management● Smart testing● Archetypes?

Page 66: Gradle - time for a new build
Page 67: Gradle - time for a new build

Resources● gradle.org● groovy.codehaus.org● sonatype.org● ant.apache.org/ivy

Page 68: Gradle - time for a new build

Questions

Page 69: Gradle - time for a new build

Contacts

Igor KhotinE-mail: [email protected]: www.ikhotin.comTwitter: chaostarter