Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Gradle: The Build System you have been waiting for!


Published on

Presented on 2016-3-8 at DevConf South Africa

Published in: Software
  • Be the first to comment

  • Be the first to like this

Gradle: The Build System you have been waiting for!

  1. 1. Corneil du Plessis Gradle: The Build system you have been waiting for! DevOps & Automation
  2. 2. Gradle: Introduction  Scope  History Lesson − Make − Ant − Maven  Gradle − What is it? − Is Groovy − Artefacts − Builtin Support − Case studies
  3. 3. Gradle: Make  Targets, dependencies, rules  Sample: CFLAGS ?= -g all: helloworld helloworld: helloworld.o # Commands start with TAB not spaces $(CC) $(LDFLAGS) -o $@ $^ helloworld.o: helloworld.c $(CC) $(CFLAGS) -c -o $@ $<  Suffix rules: .c.o: $(CC) $(CFLAGS) -c $<
  4. 4. Gradle: Ant  Projects, targets, dependency, built-in tasks, taskdef. <project name="SampleWebApp" default="all" basedir="."> <property name="" value="SampleWebApp"/> <property name="lib.dir" value="${basedir}/lib"/> <property name="work.dir" value="${basedir}/work"/> <property name="dist.dir" value="${basedir}/dist"/> <property name="src.dir" value="${basedir}/src"/> <property name="web.dir" value="${basedir}/web"/> <path id="compile.classpath"> <fileset dir="${lib.dir}"> <include name="*.jar"/> </fileset> </path>
  5. 5. Gradle: Ant – cont. <target name="all" depends="clean,compile,dist" description="Clean dirs,compile,create a WAR"/> <target name="clean" description="Delete old work and dist directories"> <delete dir="${work.dir}"/> <delete dir="${dist.dir}"/> </target> <target name="prepare" depends="clean" description="Create work dirs copy static files to work dir"> <mkdir dir="${dist.dir}"/> <mkdir dir="${work.dir}/WEB-INF/classes"/> <copy todir="${work.dir}"> <fileset dir="${web.dir}"/> </copy> </target> <target name="compile" depends="prepare" description="Compile sources and copy to WEB-INF/classes dir"> <javac srcdir="${src.dir}" destdir="${work.dir}/WEB-INF/classes"> <classpath refid="compile.classpath"/> </javac> <copy todir="${work.dir}/WEB-INF/classes"> <fileset dir="${src.dir}" excludes="**/*.java"/> </copy> </target> <target name="dist" depends="compile" description="Create WAR file for binary distribution"> <jar jarfile="${dist.dir}/${}.war" basedir="${work.dir}"/> </target> </project>
  6. 6. Gradle: Maven  POM, Goals, Lifecycle, Plugins, Profiles  Maven Repository <project xmlns="" xmlns:xsi="" xsi:schemaLocation=""> <modelVersion>4.0.0</modelVersion> <groupId>io.jumpco.samples</groupId> <artifactId>SampleWebApp</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>SampleWebApp Maven Web App</name> <url></url> <properties> <spring.version>4.2.4.RELEASE</spring.version> <junit.version>4.12</junit.version> <jdk.version>1.8</jdk.version> </properties>
  7. 7. Gradle: Maven – cont <dependencies> <!-- Spring 3 dependencies → <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> </dependencies>
  8. 8. Gradle: Maven – cont <build> <finalName>SampleWebApp</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.0</version> <configuration> <source>${jdk.version}</source> <target>${jdk.version}</target> </configuration> </plugin> </plugins> </build> </project>
  9. 9. Gradle: What is it?  Gradle is a Groovy DSL for creating build scripts  Gradle has a beautiful designed model for Tasks, Dependencies, Conventions etc.  Gradle understands Ivy and Maven repositories  Gradle can execute Ant scripts and tasks directly  This is a valid Gradle build script: apply plugin: 'war'
  10. 10. Gradle: What does it look like? build.gradle apply plugin: 'java' apply plugin: 'war' repositories { mavenCentral() } group = 'io.jumpco.samples' version = '1.0-SNAPSHOT' sourceCompatibility = 1.8 dependencies { compile “org.springframework:spring-core:$springVersion” compile “org.springframework:spring-web:$springVersion” compile “org.springframework:spring-webmvc:$springVersion” testCompile group: 'junit', name: 'junit', version: junitVersion } settings.gradle = 'SampleWebApp' springVersion=4.2.4.RELEASE junitVersion=4.11
  11. 11. Gradle: Is Groovy  DSL Handlers  Closures repositories { maven { url '' } }  Strings 'org.springframework:spring-core:' + springVersion “org.springframework:spring-core:$springVersion”
  12. 12. Gradle: Artifacts ● build.gradle – buildScript – configurations – dependencies – apply plugin – artifacts – sourceSets – other dsl sections and Groovy ● settings.gradle – subprojects ● – Global properties ● buildSrc – Custom tasks
  13. 13. Gradle: Builtin Support  Ant Projects, Tasks  Java, Jar, War, Ear  Scala, Groovy, GNU Compilers, Clang, Visual C++  Build Reporting  ANTLR  OSGi  Sonar, Pmd, Jacoco, CheckStyle, FindBugs, CodeNarc, JDepend  Maven Publish, Ivy Publish, Signing, Distribution  Jetty  Announcements (Twitter, Growl, Snarl, notify-send)
  14. 14. Gradle: IDE Support ● Eclipse ● IntelliJ ● Netbeans ● Use your imagination
  15. 15. Gradle: Create scripts  gradle init –type basic|pom|java-library  Create build.gradle and other files − Basic, Java Library, Scala Library, Groovy Library − Choose test framework − Convert pom ● IDE New Gradle Project ● Checkout lazybones at
  16. 16. Gradle: Wrapper gradle wrapper Creates gradlew, gradlew.bat, gradle folder. Small enough to checkin. ./gradlew build Downloads Gradle version and executes build task.
  17. 17. Gradle: Other  Gradle UI – Swing application  Gradle Daemon will remain running and will reload only modified scripts to improve execution time.  --continuous option. Gradle will remain running and trigger build when input artefacts modified.  New Build Model
  18. 18. Gradle: 3rd Party plugins   Google Android Development  Bintray publishing.  Artifactory  Spring IO Framework   Google App Engine  Tomcat  lessCss, minCss, minJs
  19. 19. Gradle: Cases Studies ● 2000 components, 1000 release builds per day ● Nebula. Patched Gradle. ● Enterprise Projects with > 300 modules ● Partial Local build. ● Generate documentation ● Deployment automation
  20. 20. Gradle: Summary ● Made for Customisation ● Robust Dependency Management ● Build Reporting ● The same flexible Build Model for both continuous integration and local development. ● One source of the truth
  21. 21. /* THANK YOU*/ Corneil du Plessis JumpCo (formerly TSC Technologies) Demo project: