gradle: the build system you have been waiting for
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
Gradle: Introduction
The Build System you have been waiting for.
Gradle: Introduction
Scope
History Lesson
− Make
− Ant
− Maven Gradle
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 $<
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>
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>
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>
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>
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>
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
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}
Gradle: Artifacts
build.gradle
− buildScript
− configurations
− dependencies
− apply plugin
− artifacts
− sourceSets
− other dsl sections and Groovy settings.gradle
− subprojects gradle.properties
− Global properties
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
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
Gradle: Demo
Conversion from pom
Custom Tasks
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
Gradle – Questions
Discuss on JUG Facebook
http://www.slideshare.net/CorneilduPlessis
https://www.facebook.com/groups/jozijug