Gradle: The Build system you have been waiting for

17
Gradle: The Build System Corneil du Plessis [email protected] @corneil

description

Gradle is the build system you have been waiting for or maybe the build system that has been waiting for you. The adoption rate is incredible from being the new Google Android development tools build system to most new Java opensource projects to JavaScript based front-end and back-end projects.

Transcript of Gradle: The Build system you have been waiting for

Page 1: Gradle: The Build system you have been waiting for

Gradle: The Build System

Corneil du Plessis

[email protected]@corneil

Page 2: Gradle: The Build system you have been waiting for

Gradle: Introduction

The Build System you have been waiting for.

Page 3: Gradle: The Build system you have been waiting for

Gradle: Introduction

Scope

History Lesson

− Make

− Ant

− Maven Gradle

Page 4: Gradle: The Build system you have been waiting for

Gradle: Make

Targets, dependencies, rules

Sample:CFLAGS ?= -gall: 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 $<

Page 5: Gradle: The Build system you have been waiting for

Gradle: Ant

Projects, targets, dependency, built-in tasks, taskdef. <project name="My Project" default="all" basedir=".">

<property name="app.name" value="hello"/> <property name="tcserver.home" value="/opt/tomcat-6.0.25.A.RELEASE" /> <property name="work.home" value="${basedir}/work"/> <property name="dist.home" value="${basedir}/dist"/> <property name="src.home" value="${basedir}/src"/> <property name="web.home" value="${basedir}/web"/> <path id="compile.classpath"> <fileset dir="${tcserver.home}/bin"> <include name="*.jar"/> </fileset> <pathelement location="${tcserver.home}/lib"/> <fileset dir="${tcserver.home}/lib"> <include name="*.jar"/> </fileset> </path>

Page 6: Gradle: The Build system you have been waiting for

Gradle: Ant – cont.

<target name="all" depends="clean,compile,dist" description="Clean work dirs, then compile and create a WAR"/> <target name="clean" description="Delete old work and dist directories"> <delete dir="${work.home}"/> <delete dir="${dist.home}"/> </target> <target name="prepare" depends="clean" description="Create work dirs copy static files to work dir"> <mkdir dir="${dist.home}"/> <mkdir dir="${work.home}/WEB-INF/classes"/> <copy todir="${work.home}"> <fileset dir="${web.home}"/> </copy> </target> <target name="compile" depends="prepare" description="Compile sources and copy to WEB-INF/classes dir"> <javac srcdir="${src.home}" destdir="${work.home}/WEB-INF/classes"> <classpath refid="compile.classpath"/> </javac> <copy todir="${work.home}/WEB-INF/classes"> <fileset dir="${src.home}" excludes="**/*.java"/> </copy> </target> <target name="dist" depends="compile" description="Create WAR file for binary distribution"> <jar jarfile="${dist.home}/${app.name}.war" basedir="${work.home}"/> </target>

</project>

Page 7: Gradle: The Build system you have been waiting for

Gradle: Maven

POM, Goals, Lifecycle, Plugins, Profiles

Maven Repository <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>com.mkyong</groupId> <artifactId>CounterWebApp</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>CounterWebApp Maven Webapp</name> <url>http://maven.apache.org</url> <properties> <spring.version>3.2.8.RELEASE</spring.version> <junit.version>4.11</junit.version> <jdk.version>1.6</jdk.version> </properties>

Page 8: Gradle: The Build system you have been waiting for

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>

Page 9: Gradle: The Build system you have been waiting for

Gradle: Maven – cont

<build> <finalName>CounterWebApp</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>

Page 10: Gradle: The Build system you have been waiting for

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

Page 11: Gradle: The Build system you have been waiting for

Gradle: What does it look like?

gradle.propertiesspringVersion=3.2.8.RELEASEjunitVersion=4.11

settings.gradlerootProject.name = 'CounterWebApp'

build.gradleapply plugin: 'java'apply plugin: 'war'repositories { mavenCentral()}group = 'com.mkyong'archivesBaseName = 'CounterWebApp'version = '1.0-SNAPSHOT'sourceCompatibility = 1.6dependencies { 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}

Page 12: Gradle: The Build system you have been waiting for

Gradle: Artifacts

build.gradle

− buildScript

− configurations

− dependencies

− apply plugin

− artifacts

− sourceSets

− other dsl sections and Groovy settings.gradle

− subprojects gradle.properties

− Global properties

Page 13: Gradle: The Build system you have been waiting for

Gradle: Builtin Support

Ant Projects, Tasks

Java, Jar, War, Ear

Scala, Groovy

Sonar, Pmd, Jacoco, CheckStyle, FindBugs, CodeNarc, JDepend

Maven Publish, Ivy Publish

Jetty

GNU Compilers, Clang, Visual C++

Eclipse, IdeaJ, Netbeans

Page 14: Gradle: The Build system you have been waiting for

Gradle: Create scripts

Create build.gradle and other files

− Basic, Java Library, Scala Library, Groovy Library

− Convert pom gradle init –type <project-type>

Checkout lazybones at https://github.com/pledbrook/lazybones

Page 15: Gradle: The Build system you have been waiting for

Gradle: Demo

Conversion from pom

Custom Tasks

Page 16: Gradle: The Build system you have been waiting for

Gradle: 3rd Party plugins

http://plugins.gradle.org

Google Android Development

Bintray publishing.

Artifactory

Spring IO Framework

https://github.com/nebula-plugins

Google App Engine

Tomcat

lessCss, minCss, minJs

Page 17: Gradle: The Build system you have been waiting for

Gradle – Questions

Discuss on JUG Facebook

http://www.slideshare.net/CorneilduPlessis

https://www.facebook.com/groups/jozijug