Gradle - time for a new build

6,945 views

Published on

Published in: Career, Technology

Gradle - time for a new build

  1. 1. Gradletime for a new build!time for a new build Igor Khotin E-mail: khotin@gmx.com
  2. 2. Background● 12+ years in the IT industry● 7+ years with Java● Flexible design promoter● Agile-junkie
  3. 3. What do we use?● Ant?● Maven?● Buildr?● Gradle?● ...
  4. 4. Any problems?● heavy builds?● long integration cycles?● build projects support?● build projects integration?● ...
  5. 5. How we used to build?
  6. 6. punchcards...
  7. 7. give them to an operator
  8. 8. waiting for result...
  9. 9. take the printouts...
  10. 10. debug?
  11. 11. 1977 – make
  12. 12. 2000
  13. 13. ant Complexity
  14. 14. ant Complexity hard to reuse
  15. 15. ant Complexity hard to reuse heavy build.xmls
  16. 16. ant Complexity hard to reuse heavy build.xmls Total Control
  17. 17. 2001
  18. 18. maven convention over configuration
  19. 19. maven maven central convention over configuration
  20. 20. maven maven central convention over configurationdependency management
  21. 21. maven heavy xmls maven central convention over configurationdependency management
  22. 22. maven heavy xmls hard to implement custom behavior maven central convention over configurationdependency management
  23. 23. maven heavy xmls hard to implement custom behavior maven central convention over configurationdependency management lost control
  24. 24. Gradle yesterday● Founder - Hans Dockter● 2008 – early releases● 2010 Springy Innovation Award
  25. 25. Gradle today● 1.0-rc2 released on April 25, 2012● Active community● Gradleware● Apache License, Version 2.0
  26. 26. Gradle in the wild
  27. 27. Who is that Gradle?● Build integration tool● Declarative builds● Groovy-based build DSL● Build-by-convention
  28. 28. Who is that Gradle?● Scalable – multi-project builds● Dependency management● Ease of migration● Embeddable● Deep API
  29. 29. Gradle positioning
  30. 30. Groovy and Gradlebuild.gradletask count << { 4.times { print "$it " }}> gradle -q count0 1 2 3
  31. 31. gradle task != ant taskgradle task == ant target
  32. 32. Build tree
  33. 33. Dependenciestask build << { println building...}task count(dependsOn: build) << { 4.times { print "$it " }}> gradle -q countbuilding...0 1 2 3
  34. 34. Lazy dependenciestask build(dependsOn: lazy) << { println building...}task lazy << { println so lazy...}> gradle -q helloso lazy...building...
  35. 35. 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
  36. 36. Gradle Pluginstasks – objects – conventions
  37. 37. Gradle Plugins java scala groovy cpp antrl checkstyle findbugs pmd sonar ear war osgi jetty maven
  38. 38. Java Pluginbuild.gradleapply plugin: java> gradle build...
  39. 39. Java Plugin Folder Layoutsrc/main/java Production Java sourcesrc/main/resources Production resourcessrc/test/java Test Java sourcesrc/test/resources Test resources just like maven...
  40. 40. Java Plugin Tasks Flow
  41. 41. Java Plugin Tasks Flow { println injecting... } Injectable with Groovy closures
  42. 42. Java build-cycle customizationapply plugin: javatest.doFirst { println Before testing...}test.doLast { println ...after testing.}
  43. 43. Dependency management● You can define rules for dependencies● Flexible repository handling● Works with Ivy and Maven repositories● Dynamic properties● and more...
  44. 44. Java & jarsapply plugin: javarepositories { mavenCentral()}dependencies { compile commons-lang:commons-lang:2.5 testCompile junit:junit:4.8.1}
  45. 45. Antant.importBuild build.xmltask ant << { ant.echo(message: hello from Ant) ant.zip(destfile: archive.zip) { fileset(dir: src) { include(name: **.xml) exclude(name: **.java) } }}
  46. 46. Build Lifecycle Initialization Configuration Execution
  47. 47. Multi-project builds● Arbitrary multi-project layout● Configuration injection● Separate config/execution tree● Partial builds
  48. 48. Multi-project buildsinclude project1, project2root-project/ build.gradle settings.gradle project1/ build.gradle project2/ build.gradle
  49. 49. Gradle daemon● 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
  50. 50. Apache Ant vs. Apache Maven vs. Gradle
  51. 51. 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>...
  52. 52. ant... <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>...
  53. 53. ant...<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>
  54. 54. 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>...
  55. 55. 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>
  56. 56. 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 }}
  57. 57. gradleapply plugin: javaversion="1.0-SNAPSHOT"group="grId"archivesBaseName="coc-comparison"repositories { mavenCentral()}dependencies { compile commons-lang:commons-lang:2.5 testCompile junit:junit:4.8.1}
  58. 58. Gradle problems
  59. 59. Gradle bugs
  60. 60. IDE integration
  61. 61. market penetration
  62. 62. Gradle tomorrow● Release 1.0 till the end of 2012 ● Deep import of maven projects ● Release management ● Smart testing ● Archetypes?
  63. 63. Resources● gradle.org● groovy.codehaus.org● sonatype.org● ant.apache.org/ivy
  64. 64. Questions
  65. 65. ContactsIgor KhotinE-mail: khotin@gmx.comBlog: www.ikhotin.comTwitter: chaostarter

×