SlideShare ist ein Scribd-Unternehmen logo
1 von 66
Downloaden Sie, um offline zu lesen
CS 527 @ Fall 2017, UIUC
Han Yin, Hill Randolph William, Lloyd Ramey
Presentation Contents
● WHAT:
○ Gradle as a build automation system
● WHY:
○ Comparison between Gradle and other competitors
● HOW:
○ Project structure, Gradle scripts, Plugins
○ Intro to course projects
[WHAT]
Gradle: Build Automation System
Softwares builds are cumbersome
● Dependency resolution for compiling source & test codes
○ Different forms: files, external libraries, artifacts, urls, etc.
○ Different versions for each dependency
● Continuous integration (CI)
○ Running test suites with different configurations
○ Generating reports
● Continuous delivery (CD)
○ Packaging compiled files into compressed formats, e.g. Jar, Apk, etc.
○ Deployment to servers, publishing releases
Case Study
https://gradle.org/gradle-vs-maven-performance/
● The Performance of a build system has a huge impact on the cost and engineering efficiency:
“In 2017, we worked with a 600-engineer team.
On average, the engineers each ran about 42 builds per week.
The team estimated the cost per-minute per engineer to be US$1.42,
and they work at least 44 weeks annually.”
● Build Automation Systems are invented to ease the pain of intensive repetitive tasks.
Gradle
● JVM based build automation tools:
○ Apache Ant: 2000
○ Apache Maven: 2004
○ Gradle: 2007
● Initially targeted JVM languages:
○ Java, Groovy, Scala
● Plugin based extensibility
○ Android: “com.android.application”
○ C/C++: “c”, “cpp”
● Declarative builds and build-by-convention
● DSL for dependency based programming
● Created with multi-project builds in mind
● “The first build integration tool”
○ Deep import for Ant projects / tasks
○ Fully support for existing Maven or Ivy
repository infrastructure
[WHY]
Gradle vs Ant & Maven
Apache Ant
(with Apache Ivy)
The first ‘modern’ build tool
targeting the JVM
● Released in 2000
● Configured using XML
● Highly customizable builds based
on procedural programming
● Initially only allowed local
dependencies
● Adopted Ivy for dependency
management over the network
Ant drawbacks
● Developers must write all commands to execute some task
● XML is not a good fit for procedural programming
● Requires verbose build scripts for simple tasks
● Build scripts tend to become unmanageable for non-trivial projects
● Initially required storing all dependencies alongside code
● Highly customizable
● No convention, only configuration
● XML build scripts for procedural
programming
● Dependency Management with Ivy
Ant (with Ivy)
● Highly customizable
● Convention over configuration
● Declarative Groovy DSL, allowing
imperative programming if required
● Dependency Management based on Ivy
Gradle
Apache Maven
Aiming at the pain points developers
faced when using Apache Ant
● Released in 2004
● Configured using XML
● Convention over configuration
● Relies on plugins for extending
behavior
● Introduced automated dependency
downloads
● Standardized build life-cycle
Maven drawbacks
● Poor dependency version conflict resolution
● XML configuration is strictly structured and standardized
● Complex builds can be very complicated to write
● Large project build scripts can have hundreds of lines without doing anything
advanced/extraordinary
● Difficult to customize build logic
Maven
● Difficult to customize
● Convention over configuration
● Declarative XML build scripts
● Dependency management
● Highly customizable
● Convention over configuration
● Declarative Groovy DSL, allowing
imperative programming if required
● Dependency management based on Ivy
Gradle
Buildscript
showdown
Compiling a simple Java project in the three
main JVM build systems
Ant (with Ivy)
ivy.xml:
<ivy-module version="2.0">
<info organisation="com.example" module="building-java-code"/>
<dependencies>
<dependency org="junit" name="junit" rev="4.12"/>
<dependency org="org.hamcrest" name="hamcrest-all" rev="1.3"/>
</dependencies>
</ivy-module>
Ant (with Ivy)
build.xml:
<project xmlns:ivy="antlib:org.apache.ivy.ant"
name="building-java-code" default="jar">
<path id="lib.path.id">
<fileset dir="lib" />
</path>
<target name="resolve">
<ivy:retrieve />
</target>
<target name="clean">
<delete dir="build"/>
</target>
<target name="compile" depends="resolve">
<mkdir dir="build/classes"/>
<javac srcdir=src"
destdir="build/classes"
classpathref="lib.path.id"/>
</target>
<target name="jar" depends="compile">
<mkdir dir="build/jar"/>
<jar
destfile="build/jar/building-java-code.jar"
basedir="build/classes"/>
</target>
</project>
Maven
pom.xml:
<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.example</groupId>
<artifactId>building-java-code</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
</plugin>
</plugins>
</build>
</project>
Gradle
build.gradle:
apply plugin: 'java'
group = 'com.example'
repositories {
jcenter()
}
dependencies {
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-all:1.3'
}
[HOW]
Write Gradle scripts
Gradle project
structure
Sample of a standard root project
.
+-- build/
+-- buildSrc/
+-- build.gradle
+-- settings.gradle
|
+-- sub-project-1/
| +-- …
+-- sub-project-2/
| +-- …
|
+-- gradle/
| +-- wrapper/
| +-- gradle-wrapper.jar
| +-- gradle-wrapper.properties
+-- gradlew
+-- gradlew.bat
Multi-project Builds
● Specify sub-projects in settings.gradle:
include 'sub-project-1', 'sub-project-2'
● By default, the build file is build.gradle.
○ Each sub-project has its own build script.
...
+-- settings.gradle
|
+-- build/
+-- buildSrc/
+-- build.gradle
|
+-- sub-project-1/
| +-- build/
| +-- build.gradle
|
+-- sub-project-2/
| +-- build/
| +-- build.gradle
...
Gradle Wrapper
● Ensures that the correct gradle version
is always used for the project.
● Generated by running the built-in
‘wrapper’ task.
> gradle wrapper
● Wrapper files should be committed into
VCS.
● Downloads the correct version the first
time it’s run.
.
+-- build/
+-- buildSrc/
+-- build.gradle
+-- settings.gradle
|
+-- sub-project-1/
| +-- …
+-- sub-project-2/
| +-- …
|
+-- gradle/
| +-- wrapper/
| +-- gradle-wrapper.jar
| +-- gradle-wrapper.properties
+-- gradlew
+-- gradlew.bat
Gradle Scripts
Sample of a Gradle build script
build.gradle:
apply plugin: 'java'
def pkgName = 'com.example'
group = pkgName
repositories {
jcenter()
}
dependencies {
testCompile 'junit:junit:4.12'
testCompile
'org.hamcrest:hamcrest-all:1.3'
}
Gradle scripts
● First, Gradle scripts are configuration scripts.
○ As a script executes, it configures a Delegate Object of itself.
○ Then, the properties and methods of the Delegate Object are available to use in the script.
● Delegate types:
○ Build script: build.gradle Project
○ Init script: init.gradle Gradle
○ Settings script: settings.gradle Settings
● Second, Each Gradle script implements the Script interface, which defines a number of properties
and methods which you can use in the script.
Gradle scripts: Delegate objects
build.gradle:
apply plugin: 'java'
group = 'com.example'
repositories {
jcenter()
}
dependencies {
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-all:1.3'
}
test {
reports.html.enabled = false
}
● Delegate Object: Project
○ group
○ apply()
○ repositories()
○ dependencies()
● Plugin: Java
○ test()
○ Dependency configurations:
■ junit, hamcrest...
Gradle scripts: Build script structure
● A build script is made up of zero or more Statements and Script Blocks.
○ Statements can include:
■ local variable declarations, method calls, property assignments.
○ A Script Block is a method call which takes a closure as a parameter.
The closure is treated as a configuration closure which configures the
Delegate Object as it executes.
Gradle scripts: Statements
build.gradle:
apply plugin: 'java'
def pkgName = 'com.example' local variable declaration
group = pkgName property assignment
repositories {
jcenter() method call
}
dependencies { script block ? ? ?
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-all:1.3'
}
Gradle DSL
● Gradle script is also a Groovy script, therefore it can contain those elements allowed in Groovy:
○ Method definitions, Class definitions, Annotations, Comments, etc.
/* Get password from Mac OS Keychain */
def getPassword(String keyChain) {
def stdout = new ByteArrayOutputStream()
def stderr = new ByteArrayOutputStream()
exec {
commandLine 'security', 'find-generic-password',
keyChain
standardOutput = stdout
errorOutput = stderr
ignoreExitValue true
}
stderr.toString().trim().drop(10).replaceAll('"','')
}
// A customized task to print a greeting
class GreetingTask extends DefaultTask {
@TaskAction
def greet() {
println 'Greetings!'
}
}
// Create a task using the task type
task hello(type: GreetingTask)
Gradle scripts: Script blocks
dependencies()
dependencies({ A method call that takes a closure as a parameter.
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-all:1.3'
})
dependencies(){ Since the closure is the last parameter,
...... it can be moved out of the parentheses.
}
dependencies { Parentheses can be omitted if no ambiguity:
...... A script block!
}
● A script block is a method call which takes a closure as a parameter.
Gradle Tasks
Customize the Gradle build
process with your own tasks
● Everything in Gradle sits on top of
two basic concepts:
○ Projects
○ Tasks
Gradle Tasks
● A Project includes a collection of Tasks.
● A Task represents a single atomic piece of work for a build.
○ E.g. compiling classes, generating javadoc, etc.
● Each task belongs to a Project, and has a name for reference within this project.
● A task may have dependencies on other tasks, or might be scheduled to always run after
another task.
Gradle Tasks
● To view the tasks in groups:
○ gradle tasks
○ gradle tasks --all
● Gradle supports two types of task:
○ One is the simple task
○ The other is the enhanced task
Gradle Tasks: Simple Task
● One is the simple task:
○ You define the task with an action
closure to determine the behaviour of
the task.
○ Good for implementing one-off tasks
in your build script.
task taskX(dependsOn: 'taskY'){
doLast {
println 'taskX'
}
}
task taskY {
doLast {
println 'taskY'
}
}
> gradle taskX
Gradle Tasks: Simple Task
task hello {
doLast {
println 'Hello World'
}
doFirst {
if(!usingEclipse) {
throw new StopExecutionException()
}
}
onlyIf {
project.hasProperty('usingEclipse')
}
}
● Code specified in doLast will be run after all
other task actions have been executed
● Code specified in doFirst will be run before
all other task actions have been executed
● Tasks can be optionally skipped if onlyIf
closure evaluates to false
Gradle Tasks: Enhanced Task
● The other is the enhanced task:
○ The behaviour is built into the task, and
the task provides some properties.
○ You don’t need to implement the task
behaviour like simple tasks, but simply
declare the task and configure the task
using its properties.
○ Most Gradle plugins use enhanced tasks.
task copy(type: Copy) {
from 'resources'
into 'target'
include('**/*.txt', '**/*.xml',
'**/*.properties' )
}
Gradle Build
Lifecycle
● There are three phases in a build:
○ Initialization
○ Configuration
○ Execution
Gradle Build Lifecycle: Initialization
● Gradle determines which projects are going to take part in the build, and creates a Project
instance for each of these projects.
● Settings.gradle is evaluated if present.
○ A multi-project build must have this file in the root project!
○ This is the only place to set the root project name, otherwise it defaults to the folder name.
○ Can reference gradle properties.
○ Can modify plugin resolution for projects.
Gradle Build Lifecycle: Configuration
● Gradle configure the project objects on “configuration on demand” mode.
○ Only executes the build.gradle file of projects that are participating in the build.
○ Provides a performance boost for large multi-project builds.
● All the tasks are configured during this stage.
○ But the action scripts are NOT NECESSARILY executed.
■ i.e. doFirst, doLast, onlyIf, etc.
Gradle Build Lifecycle: Execution
● Gradle determines the subset of tasks to execute.
○ Determined by the task names passed to the gradle command
● Gradle then executes each of the selected tasks.
○ Execution is ordered by dependencies
○ Parallel task execution is an incubating feature
○ Any task failures will cause the build to fail and stop prematurely
A sample Java build script
https://github.com/uber-common/infer-plugin/blob/master/infer-plugin/build.gradle
Gradle Plugins ● Extend Gradle DSL by adding
capabilities to Gradle projects
● Large collection of plugins built into
Gradle
● Many third-party plugins available
Java Plugin
● apply plugin: 'java'
● The java plugin allows Gradle to compile
java source, as well as run JUnit / TestNG
based tests and bundle build artifacts.
● It also serves as the basis for many other
Gradle plugins.
Java Plugin: Project Structure
● Gradle uses the same directory
conventions as Maven, i.e. convention
over configuration
● Configurable in the build script’s sourceSets:
sourceSets {
main {
java {
srcDirs = ['src/java']
}
resources {
srcDirs = ['src/resources']
}
}
}
Java Plugin: Task Depencencies
Java Plugin: Dependency Management
● You must specify which repositories to
pull dependencies from.
● Works with either Maven repositories or
Ivy repositories.
● Provides shortcuts for the two major
Maven repositories.
○ MavenCentral
○ JCenter
● Easy to specify custom repositories.
apply plugin: 'java'
...
repositories {
mavenCentral()
jcenter()
maven {
url 'http://my-repo/'
}
ivy {
url 'http://my-repo/'
}
}
Java Plugin: Dependency Management
● Maven dependencies are specified using:
○ Group ID, Artifact ID, Version
● Local jars can be included using file
collections
● Projects included by passing a reference
to the subproject
apply plugin: 'java'
...
dependencies {
compile 'commons-io:commons-io:2.6'
testCompile 'junit:junit:4.12'
runtime fileTree(dir:'libs', include
'*.jar')
testRuntime files('libs/a.jar')
compile project(':other')
}
Java Plugin: Dependency Management
● You must specify which repositories to
pull dependencies from
● Works with either Maven repositories or
Ivy repositories
● Provides shortcuts for the two major
Maven repositories
● Easy to specify custom repositories
apply plugin: 'java'
...
repositories {
mavenCentral()
jcenter()
maven {
url 'http://my-repo/'
}
}
Android Plugin
● apply plugin:
'com.android.application'
● The Android plugin adds functionality to
Gradle for building, testing, and
releasing android applications
independently of Android Studio / Eclipse.
● It is a third-party plugin developed by
Google, and typically updated in
lock-step with Android Studio.
● As the Android plugin isn’t built into gradle,
and Google does not publish it to Gradle’s
plugin portal, you have to tell gradle where
to find the plugin.
● Gradle 4.1 and higher includes the ‘google()’
repository shortcut.
Other Common Plugins
● java-base
○ Adds Java compilation, testing and bundling capabilities to a project.
○ It serves as the basis for many of the other Gradle plugins.
● java, groovy-base
○ Adds support for building Groovy projects.
● java, scala-base
○ Adds support for building Scala projects.
Custom Plugin
● apply plugin: 'my.custom.plugin'
● Gradle allows you to implement your own plugins, so you can reuse your build logic, and
share it with others
● You can implement a Gradle plugin in any language that ends up compiled as bytecode.
● Gradle API has been designed to work well with Groovy, Java or Kotlin
Custom Plugin: Packaging
● Build Script
○ Can include the source for the plugin directly in the build script.
○ Pro: plugin is automatically compiled and included in the classpath of the build script.
○ Con: Plugin is not visible outside the build script.
● Within a project
○ Pro: plugin is visible to every build script used by the build.
○ Con: it is not visible outside the build, and so you cannot reuse the plugin outside the build it is defined in.
● Standalone project
○ Project produces and publishes a JAR which you can then use in multiple builds and share with others.
○ Generally, this JAR might include some plugins, or bundle several related task classes into a single library.
[HOW]
Course Projects
Visual Studio Code
Gradle language
extension
Han Yin
● Syntax highlighting
● Keyword auto-complete proposal
● Duplication validation
Challenges
● Grammatical features of Gradle DSL
○ Custom AST transformations
○ Confusing script blocks
○ Each property is created with a setter with the exact same name
● Develop a language server using TypeScript
○ Npm in Node.js, TypeScript compilers, etc.
Gradle DSL Grammar
● Custom AST transformations
○ TaskContainer
Gradle DSL Grammar
● Confusing script blocks
○ E.g. NamedDomainObjectContainer
Gradle DSL Grammar
● Each property is created with a setter with the exact same name
Check it out!
Homepage on Marketplace
STARTS plugin
Hill, Randolph William
apply plugin: 'java'
apply plugin: 'edu.illinois.starts'
buildscript {
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
classpath
"edu.illinois:starts-maven-plugin:1.4-
SNAPSHOT"
}
}
STARTS plugin
● Video:
https://www.dropbox.com/s/f7g70tcys5zrm26/Starts_Update.mov?dl=0
Starts Plugin Goals
● Create corresponding Gradle tasks for
each Maven goals
● Evaluate STARTS on gradle specific
project and compare with Ekstazi
# Remove all STARTS artifacts
./gradlew startsClean
# Changes since last time STARTS was run
./gradlew startsDiff
# Types impacted by changes
./gradlew startsImpacted
# Tests affected by the most recent changes
./gradlew startsSelect
# To perform RTS using STARTS
./gradlew starts
● Run tests against production-like
systems using docker
Docker Testing
plugin
Ramey, Lloyd Nelson
Docker Testing plugin
● Video:
https://drive.google.com/file/d/1flSwgmg6bu1MM_TuVlPNL-Efx3rek20_/view
Conclusion
Conclusion
● Gradle is a build automation system to configure, extend and customize the
build process mainly for JVM languages.
● Gradle combines Ant’s power and flexibility with Maven’s life-cycle and ease of
use by adopting a Groovy-based DSL for writing declarative build scripts with
better concision and readability.
● Gradle provides outstanding extensibility and customizability by supporting
various plugins.
Thank you!

Weitere ähnliche Inhalte

Was ist angesagt?

Basics of reflection in java
Basics of reflection in javaBasics of reflection in java
Basics of reflection in javakim.mens
 
Quick introduction to Java Garbage Collector (JVM GC)
Quick introduction to Java Garbage Collector (JVM GC)Quick introduction to Java Garbage Collector (JVM GC)
Quick introduction to Java Garbage Collector (JVM GC)Marcos García
 
GraalVM Overview Compact version
GraalVM Overview Compact versionGraalVM Overview Compact version
GraalVM Overview Compact versionscalaconfjp
 
Gradle - the Enterprise Automation Tool
Gradle  - the Enterprise Automation ToolGradle  - the Enterprise Automation Tool
Gradle - the Enterprise Automation ToolIzzet Mustafaiev
 
Java 9 New Features
Java 9 New FeaturesJava 9 New Features
Java 9 New FeaturesAli BAKAN
 
Graal in GraalVM - A New JIT Compiler
Graal in GraalVM - A New JIT CompilerGraal in GraalVM - A New JIT Compiler
Graal in GraalVM - A New JIT CompilerKoichi Sakata
 
Strings in Java
Strings in Java Strings in Java
Strings in Java Hitesh-Java
 
Java 10 New Features
Java 10 New FeaturesJava 10 New Features
Java 10 New FeaturesAli BAKAN
 
Java 9/10/11 - What's new and why you should upgrade
Java 9/10/11 - What's new and why you should upgradeJava 9/10/11 - What's new and why you should upgrade
Java 9/10/11 - What's new and why you should upgradeSimone Bordet
 
Top 10 reasons to migrate to Gradle
Top 10 reasons to migrate to GradleTop 10 reasons to migrate to Gradle
Top 10 reasons to migrate to GradleStrannik_2013
 
Maven Basics - Explained
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - ExplainedSmita Prasad
 
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.David Gómez García
 
API Asynchrones en Java 8
API Asynchrones en Java 8API Asynchrones en Java 8
API Asynchrones en Java 8José Paumard
 

Was ist angesagt? (20)

Basics of reflection in java
Basics of reflection in javaBasics of reflection in java
Basics of reflection in java
 
Quick introduction to Java Garbage Collector (JVM GC)
Quick introduction to Java Garbage Collector (JVM GC)Quick introduction to Java Garbage Collector (JVM GC)
Quick introduction to Java Garbage Collector (JVM GC)
 
GraalVM Overview Compact version
GraalVM Overview Compact versionGraalVM Overview Compact version
GraalVM Overview Compact version
 
Gradle - the Enterprise Automation Tool
Gradle  - the Enterprise Automation ToolGradle  - the Enterprise Automation Tool
Gradle - the Enterprise Automation Tool
 
Java 9 New Features
Java 9 New FeaturesJava 9 New Features
Java 9 New Features
 
Java 9 Features
Java 9 FeaturesJava 9 Features
Java 9 Features
 
Java Concurrency by Example
Java Concurrency by ExampleJava Concurrency by Example
Java Concurrency by Example
 
Maven
MavenMaven
Maven
 
Graal in GraalVM - A New JIT Compiler
Graal in GraalVM - A New JIT CompilerGraal in GraalVM - A New JIT Compiler
Graal in GraalVM - A New JIT Compiler
 
Strings in Java
Strings in Java Strings in Java
Strings in Java
 
Java 10 New Features
Java 10 New FeaturesJava 10 New Features
Java 10 New Features
 
Gradle
GradleGradle
Gradle
 
Java 9/10/11 - What's new and why you should upgrade
Java 9/10/11 - What's new and why you should upgradeJava 9/10/11 - What's new and why you should upgrade
Java 9/10/11 - What's new and why you should upgrade
 
Maven tutorial
Maven tutorialMaven tutorial
Maven tutorial
 
Top 10 reasons to migrate to Gradle
Top 10 reasons to migrate to GradleTop 10 reasons to migrate to Gradle
Top 10 reasons to migrate to Gradle
 
Maven Basics - Explained
Maven Basics - ExplainedMaven Basics - Explained
Maven Basics - Explained
 
1 .java basic
1 .java basic1 .java basic
1 .java basic
 
Heap & thread dump
Heap & thread dumpHeap & thread dump
Heap & thread dump
 
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.
 
API Asynchrones en Java 8
API Asynchrones en Java 8API Asynchrones en Java 8
API Asynchrones en Java 8
 

Ähnlich wie Gradle

Gradle build automation tool
Gradle   build automation toolGradle   build automation tool
Gradle build automation toolIoan Eugen Stan
 
Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Ryan Cuprak
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with GradleRyan Cuprak
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with GradleRyan Cuprak
 
Gradle,the new build system for android
Gradle,the new build system for androidGradle,the new build system for android
Gradle,the new build system for androidzhang ghui
 
Gradle.Enemy at the gates
Gradle.Enemy at the gatesGradle.Enemy at the gates
Gradle.Enemy at the gatesStrannik_2013
 
[20200720]cloud native develoment - Nelson Lin
[20200720]cloud native develoment - Nelson Lin[20200720]cloud native develoment - Nelson Lin
[20200720]cloud native develoment - Nelson LinHanLing Shen
 
Gradle - Build system evolved
Gradle - Build system evolvedGradle - Build system evolved
Gradle - Build system evolvedBhagwat Kumar
 
Android gradle-build-system-overview
Android gradle-build-system-overviewAndroid gradle-build-system-overview
Android gradle-build-system-overviewKevin He
 
Grunt training deck
Grunt training deckGrunt training deck
Grunt training deckJames Ford
 
Gradle 2.Write once, builde everywhere
Gradle 2.Write once, builde everywhereGradle 2.Write once, builde everywhere
Gradle 2.Write once, builde everywhereStrannik_2013
 
A New CLI for Spring Developer Productivity
A New CLI for Spring Developer ProductivityA New CLI for Spring Developer Productivity
A New CLI for Spring Developer ProductivityVMware Tanzu
 
Becoming A Drupal Master Builder
Becoming A Drupal Master BuilderBecoming A Drupal Master Builder
Becoming A Drupal Master BuilderPhilip Norton
 
Modern Web-site Development Pipeline
Modern Web-site Development PipelineModern Web-site Development Pipeline
Modern Web-site Development PipelineGlobalLogic Ukraine
 

Ähnlich wie Gradle (20)

Introduction to gradle
Introduction to gradleIntroduction to gradle
Introduction to gradle
 
Gradle build automation tool
Gradle   build automation toolGradle   build automation tool
Gradle build automation tool
 
ICONUK 2015 - Gradle Up!
ICONUK 2015 - Gradle Up!ICONUK 2015 - Gradle Up!
ICONUK 2015 - Gradle Up!
 
Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]
 
Gradle explained
Gradle explainedGradle explained
Gradle explained
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
 
Gradle,the new build system for android
Gradle,the new build system for androidGradle,the new build system for android
Gradle,the new build system for android
 
Grails 101
Grails 101Grails 101
Grails 101
 
Gradle : An introduction
Gradle : An introduction Gradle : An introduction
Gradle : An introduction
 
Gradle.Enemy at the gates
Gradle.Enemy at the gatesGradle.Enemy at the gates
Gradle.Enemy at the gates
 
[20200720]cloud native develoment - Nelson Lin
[20200720]cloud native develoment - Nelson Lin[20200720]cloud native develoment - Nelson Lin
[20200720]cloud native develoment - Nelson Lin
 
Gradle - Build system evolved
Gradle - Build system evolvedGradle - Build system evolved
Gradle - Build system evolved
 
Gradle - Build System
Gradle - Build SystemGradle - Build System
Gradle - Build System
 
Android gradle-build-system-overview
Android gradle-build-system-overviewAndroid gradle-build-system-overview
Android gradle-build-system-overview
 
Grunt training deck
Grunt training deckGrunt training deck
Grunt training deck
 
Gradle 2.Write once, builde everywhere
Gradle 2.Write once, builde everywhereGradle 2.Write once, builde everywhere
Gradle 2.Write once, builde everywhere
 
A New CLI for Spring Developer Productivity
A New CLI for Spring Developer ProductivityA New CLI for Spring Developer Productivity
A New CLI for Spring Developer Productivity
 
Becoming A Drupal Master Builder
Becoming A Drupal Master BuilderBecoming A Drupal Master Builder
Becoming A Drupal Master Builder
 
Modern Web-site Development Pipeline
Modern Web-site Development PipelineModern Web-site Development Pipeline
Modern Web-site Development Pipeline
 

Kürzlich hochgeladen

Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 

Kürzlich hochgeladen (20)

Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 

Gradle

  • 1. CS 527 @ Fall 2017, UIUC Han Yin, Hill Randolph William, Lloyd Ramey
  • 2. Presentation Contents ● WHAT: ○ Gradle as a build automation system ● WHY: ○ Comparison between Gradle and other competitors ● HOW: ○ Project structure, Gradle scripts, Plugins ○ Intro to course projects
  • 4. Softwares builds are cumbersome ● Dependency resolution for compiling source & test codes ○ Different forms: files, external libraries, artifacts, urls, etc. ○ Different versions for each dependency ● Continuous integration (CI) ○ Running test suites with different configurations ○ Generating reports ● Continuous delivery (CD) ○ Packaging compiled files into compressed formats, e.g. Jar, Apk, etc. ○ Deployment to servers, publishing releases
  • 5. Case Study https://gradle.org/gradle-vs-maven-performance/ ● The Performance of a build system has a huge impact on the cost and engineering efficiency: “In 2017, we worked with a 600-engineer team. On average, the engineers each ran about 42 builds per week. The team estimated the cost per-minute per engineer to be US$1.42, and they work at least 44 weeks annually.” ● Build Automation Systems are invented to ease the pain of intensive repetitive tasks.
  • 6. Gradle ● JVM based build automation tools: ○ Apache Ant: 2000 ○ Apache Maven: 2004 ○ Gradle: 2007 ● Initially targeted JVM languages: ○ Java, Groovy, Scala ● Plugin based extensibility ○ Android: “com.android.application” ○ C/C++: “c”, “cpp” ● Declarative builds and build-by-convention ● DSL for dependency based programming ● Created with multi-project builds in mind ● “The first build integration tool” ○ Deep import for Ant projects / tasks ○ Fully support for existing Maven or Ivy repository infrastructure
  • 8. Apache Ant (with Apache Ivy) The first ‘modern’ build tool targeting the JVM ● Released in 2000 ● Configured using XML ● Highly customizable builds based on procedural programming ● Initially only allowed local dependencies ● Adopted Ivy for dependency management over the network
  • 9. Ant drawbacks ● Developers must write all commands to execute some task ● XML is not a good fit for procedural programming ● Requires verbose build scripts for simple tasks ● Build scripts tend to become unmanageable for non-trivial projects ● Initially required storing all dependencies alongside code
  • 10. ● Highly customizable ● No convention, only configuration ● XML build scripts for procedural programming ● Dependency Management with Ivy Ant (with Ivy) ● Highly customizable ● Convention over configuration ● Declarative Groovy DSL, allowing imperative programming if required ● Dependency Management based on Ivy Gradle
  • 11. Apache Maven Aiming at the pain points developers faced when using Apache Ant ● Released in 2004 ● Configured using XML ● Convention over configuration ● Relies on plugins for extending behavior ● Introduced automated dependency downloads ● Standardized build life-cycle
  • 12. Maven drawbacks ● Poor dependency version conflict resolution ● XML configuration is strictly structured and standardized ● Complex builds can be very complicated to write ● Large project build scripts can have hundreds of lines without doing anything advanced/extraordinary ● Difficult to customize build logic
  • 13. Maven ● Difficult to customize ● Convention over configuration ● Declarative XML build scripts ● Dependency management ● Highly customizable ● Convention over configuration ● Declarative Groovy DSL, allowing imperative programming if required ● Dependency management based on Ivy Gradle
  • 14. Buildscript showdown Compiling a simple Java project in the three main JVM build systems
  • 15. Ant (with Ivy) ivy.xml: <ivy-module version="2.0"> <info organisation="com.example" module="building-java-code"/> <dependencies> <dependency org="junit" name="junit" rev="4.12"/> <dependency org="org.hamcrest" name="hamcrest-all" rev="1.3"/> </dependencies> </ivy-module>
  • 16. Ant (with Ivy) build.xml: <project xmlns:ivy="antlib:org.apache.ivy.ant" name="building-java-code" default="jar"> <path id="lib.path.id"> <fileset dir="lib" /> </path> <target name="resolve"> <ivy:retrieve /> </target> <target name="clean"> <delete dir="build"/> </target> <target name="compile" depends="resolve"> <mkdir dir="build/classes"/> <javac srcdir=src" destdir="build/classes" classpathref="lib.path.id"/> </target> <target name="jar" depends="compile"> <mkdir dir="build/jar"/> <jar destfile="build/jar/building-java-code.jar" basedir="build/classes"/> </target> </project>
  • 17. Maven pom.xml: <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.example</groupId> <artifactId>building-java-code</artifactId> <packaging>jar</packaging> <version>1.0</version> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> <dependency> <groupId>org.hamcrest</groupId> <artifactId>hamcrest-all</artifactId> <version>1.3</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> </plugin> </plugins> </build> </project>
  • 18. Gradle build.gradle: apply plugin: 'java' group = 'com.example' repositories { jcenter() } dependencies { testCompile 'junit:junit:4.12' testCompile 'org.hamcrest:hamcrest-all:1.3' }
  • 20. Gradle project structure Sample of a standard root project . +-- build/ +-- buildSrc/ +-- build.gradle +-- settings.gradle | +-- sub-project-1/ | +-- … +-- sub-project-2/ | +-- … | +-- gradle/ | +-- wrapper/ | +-- gradle-wrapper.jar | +-- gradle-wrapper.properties +-- gradlew +-- gradlew.bat
  • 21. Multi-project Builds ● Specify sub-projects in settings.gradle: include 'sub-project-1', 'sub-project-2' ● By default, the build file is build.gradle. ○ Each sub-project has its own build script. ... +-- settings.gradle | +-- build/ +-- buildSrc/ +-- build.gradle | +-- sub-project-1/ | +-- build/ | +-- build.gradle | +-- sub-project-2/ | +-- build/ | +-- build.gradle ...
  • 22. Gradle Wrapper ● Ensures that the correct gradle version is always used for the project. ● Generated by running the built-in ‘wrapper’ task. > gradle wrapper ● Wrapper files should be committed into VCS. ● Downloads the correct version the first time it’s run. . +-- build/ +-- buildSrc/ +-- build.gradle +-- settings.gradle | +-- sub-project-1/ | +-- … +-- sub-project-2/ | +-- … | +-- gradle/ | +-- wrapper/ | +-- gradle-wrapper.jar | +-- gradle-wrapper.properties +-- gradlew +-- gradlew.bat
  • 23. Gradle Scripts Sample of a Gradle build script build.gradle: apply plugin: 'java' def pkgName = 'com.example' group = pkgName repositories { jcenter() } dependencies { testCompile 'junit:junit:4.12' testCompile 'org.hamcrest:hamcrest-all:1.3' }
  • 24. Gradle scripts ● First, Gradle scripts are configuration scripts. ○ As a script executes, it configures a Delegate Object of itself. ○ Then, the properties and methods of the Delegate Object are available to use in the script. ● Delegate types: ○ Build script: build.gradle Project ○ Init script: init.gradle Gradle ○ Settings script: settings.gradle Settings ● Second, Each Gradle script implements the Script interface, which defines a number of properties and methods which you can use in the script.
  • 25. Gradle scripts: Delegate objects build.gradle: apply plugin: 'java' group = 'com.example' repositories { jcenter() } dependencies { testCompile 'junit:junit:4.12' testCompile 'org.hamcrest:hamcrest-all:1.3' } test { reports.html.enabled = false } ● Delegate Object: Project ○ group ○ apply() ○ repositories() ○ dependencies() ● Plugin: Java ○ test() ○ Dependency configurations: ■ junit, hamcrest...
  • 26. Gradle scripts: Build script structure ● A build script is made up of zero or more Statements and Script Blocks. ○ Statements can include: ■ local variable declarations, method calls, property assignments. ○ A Script Block is a method call which takes a closure as a parameter. The closure is treated as a configuration closure which configures the Delegate Object as it executes.
  • 27. Gradle scripts: Statements build.gradle: apply plugin: 'java' def pkgName = 'com.example' local variable declaration group = pkgName property assignment repositories { jcenter() method call } dependencies { script block ? ? ? testCompile 'junit:junit:4.12' testCompile 'org.hamcrest:hamcrest-all:1.3' }
  • 28. Gradle DSL ● Gradle script is also a Groovy script, therefore it can contain those elements allowed in Groovy: ○ Method definitions, Class definitions, Annotations, Comments, etc. /* Get password from Mac OS Keychain */ def getPassword(String keyChain) { def stdout = new ByteArrayOutputStream() def stderr = new ByteArrayOutputStream() exec { commandLine 'security', 'find-generic-password', keyChain standardOutput = stdout errorOutput = stderr ignoreExitValue true } stderr.toString().trim().drop(10).replaceAll('"','') } // A customized task to print a greeting class GreetingTask extends DefaultTask { @TaskAction def greet() { println 'Greetings!' } } // Create a task using the task type task hello(type: GreetingTask)
  • 29. Gradle scripts: Script blocks dependencies() dependencies({ A method call that takes a closure as a parameter. testCompile 'junit:junit:4.12' testCompile 'org.hamcrest:hamcrest-all:1.3' }) dependencies(){ Since the closure is the last parameter, ...... it can be moved out of the parentheses. } dependencies { Parentheses can be omitted if no ambiguity: ...... A script block! } ● A script block is a method call which takes a closure as a parameter.
  • 30. Gradle Tasks Customize the Gradle build process with your own tasks ● Everything in Gradle sits on top of two basic concepts: ○ Projects ○ Tasks
  • 31. Gradle Tasks ● A Project includes a collection of Tasks. ● A Task represents a single atomic piece of work for a build. ○ E.g. compiling classes, generating javadoc, etc. ● Each task belongs to a Project, and has a name for reference within this project. ● A task may have dependencies on other tasks, or might be scheduled to always run after another task.
  • 32. Gradle Tasks ● To view the tasks in groups: ○ gradle tasks ○ gradle tasks --all ● Gradle supports two types of task: ○ One is the simple task ○ The other is the enhanced task
  • 33. Gradle Tasks: Simple Task ● One is the simple task: ○ You define the task with an action closure to determine the behaviour of the task. ○ Good for implementing one-off tasks in your build script. task taskX(dependsOn: 'taskY'){ doLast { println 'taskX' } } task taskY { doLast { println 'taskY' } } > gradle taskX
  • 34. Gradle Tasks: Simple Task task hello { doLast { println 'Hello World' } doFirst { if(!usingEclipse) { throw new StopExecutionException() } } onlyIf { project.hasProperty('usingEclipse') } } ● Code specified in doLast will be run after all other task actions have been executed ● Code specified in doFirst will be run before all other task actions have been executed ● Tasks can be optionally skipped if onlyIf closure evaluates to false
  • 35. Gradle Tasks: Enhanced Task ● The other is the enhanced task: ○ The behaviour is built into the task, and the task provides some properties. ○ You don’t need to implement the task behaviour like simple tasks, but simply declare the task and configure the task using its properties. ○ Most Gradle plugins use enhanced tasks. task copy(type: Copy) { from 'resources' into 'target' include('**/*.txt', '**/*.xml', '**/*.properties' ) }
  • 36. Gradle Build Lifecycle ● There are three phases in a build: ○ Initialization ○ Configuration ○ Execution
  • 37. Gradle Build Lifecycle: Initialization ● Gradle determines which projects are going to take part in the build, and creates a Project instance for each of these projects. ● Settings.gradle is evaluated if present. ○ A multi-project build must have this file in the root project! ○ This is the only place to set the root project name, otherwise it defaults to the folder name. ○ Can reference gradle properties. ○ Can modify plugin resolution for projects.
  • 38. Gradle Build Lifecycle: Configuration ● Gradle configure the project objects on “configuration on demand” mode. ○ Only executes the build.gradle file of projects that are participating in the build. ○ Provides a performance boost for large multi-project builds. ● All the tasks are configured during this stage. ○ But the action scripts are NOT NECESSARILY executed. ■ i.e. doFirst, doLast, onlyIf, etc.
  • 39. Gradle Build Lifecycle: Execution ● Gradle determines the subset of tasks to execute. ○ Determined by the task names passed to the gradle command ● Gradle then executes each of the selected tasks. ○ Execution is ordered by dependencies ○ Parallel task execution is an incubating feature ○ Any task failures will cause the build to fail and stop prematurely
  • 40. A sample Java build script https://github.com/uber-common/infer-plugin/blob/master/infer-plugin/build.gradle
  • 41. Gradle Plugins ● Extend Gradle DSL by adding capabilities to Gradle projects ● Large collection of plugins built into Gradle ● Many third-party plugins available
  • 42. Java Plugin ● apply plugin: 'java' ● The java plugin allows Gradle to compile java source, as well as run JUnit / TestNG based tests and bundle build artifacts. ● It also serves as the basis for many other Gradle plugins.
  • 43. Java Plugin: Project Structure ● Gradle uses the same directory conventions as Maven, i.e. convention over configuration ● Configurable in the build script’s sourceSets: sourceSets { main { java { srcDirs = ['src/java'] } resources { srcDirs = ['src/resources'] } } }
  • 44. Java Plugin: Task Depencencies
  • 45. Java Plugin: Dependency Management ● You must specify which repositories to pull dependencies from. ● Works with either Maven repositories or Ivy repositories. ● Provides shortcuts for the two major Maven repositories. ○ MavenCentral ○ JCenter ● Easy to specify custom repositories. apply plugin: 'java' ... repositories { mavenCentral() jcenter() maven { url 'http://my-repo/' } ivy { url 'http://my-repo/' } }
  • 46. Java Plugin: Dependency Management ● Maven dependencies are specified using: ○ Group ID, Artifact ID, Version ● Local jars can be included using file collections ● Projects included by passing a reference to the subproject apply plugin: 'java' ... dependencies { compile 'commons-io:commons-io:2.6' testCompile 'junit:junit:4.12' runtime fileTree(dir:'libs', include '*.jar') testRuntime files('libs/a.jar') compile project(':other') }
  • 47. Java Plugin: Dependency Management ● You must specify which repositories to pull dependencies from ● Works with either Maven repositories or Ivy repositories ● Provides shortcuts for the two major Maven repositories ● Easy to specify custom repositories apply plugin: 'java' ... repositories { mavenCentral() jcenter() maven { url 'http://my-repo/' } }
  • 48. Android Plugin ● apply plugin: 'com.android.application' ● The Android plugin adds functionality to Gradle for building, testing, and releasing android applications independently of Android Studio / Eclipse. ● It is a third-party plugin developed by Google, and typically updated in lock-step with Android Studio. ● As the Android plugin isn’t built into gradle, and Google does not publish it to Gradle’s plugin portal, you have to tell gradle where to find the plugin. ● Gradle 4.1 and higher includes the ‘google()’ repository shortcut.
  • 49. Other Common Plugins ● java-base ○ Adds Java compilation, testing and bundling capabilities to a project. ○ It serves as the basis for many of the other Gradle plugins. ● java, groovy-base ○ Adds support for building Groovy projects. ● java, scala-base ○ Adds support for building Scala projects.
  • 50. Custom Plugin ● apply plugin: 'my.custom.plugin' ● Gradle allows you to implement your own plugins, so you can reuse your build logic, and share it with others ● You can implement a Gradle plugin in any language that ends up compiled as bytecode. ● Gradle API has been designed to work well with Groovy, Java or Kotlin
  • 51. Custom Plugin: Packaging ● Build Script ○ Can include the source for the plugin directly in the build script. ○ Pro: plugin is automatically compiled and included in the classpath of the build script. ○ Con: Plugin is not visible outside the build script. ● Within a project ○ Pro: plugin is visible to every build script used by the build. ○ Con: it is not visible outside the build, and so you cannot reuse the plugin outside the build it is defined in. ● Standalone project ○ Project produces and publishes a JAR which you can then use in multiple builds and share with others. ○ Generally, this JAR might include some plugins, or bundle several related task classes into a single library.
  • 53. Visual Studio Code Gradle language extension Han Yin ● Syntax highlighting ● Keyword auto-complete proposal ● Duplication validation
  • 54. Challenges ● Grammatical features of Gradle DSL ○ Custom AST transformations ○ Confusing script blocks ○ Each property is created with a setter with the exact same name ● Develop a language server using TypeScript ○ Npm in Node.js, TypeScript compilers, etc.
  • 55. Gradle DSL Grammar ● Custom AST transformations ○ TaskContainer
  • 56. Gradle DSL Grammar ● Confusing script blocks ○ E.g. NamedDomainObjectContainer
  • 57. Gradle DSL Grammar ● Each property is created with a setter with the exact same name
  • 58. Check it out! Homepage on Marketplace
  • 59. STARTS plugin Hill, Randolph William apply plugin: 'java' apply plugin: 'edu.illinois.starts' buildscript { repositories { mavenCentral() mavenLocal() } dependencies { classpath "edu.illinois:starts-maven-plugin:1.4- SNAPSHOT" } }
  • 61. Starts Plugin Goals ● Create corresponding Gradle tasks for each Maven goals ● Evaluate STARTS on gradle specific project and compare with Ekstazi # Remove all STARTS artifacts ./gradlew startsClean # Changes since last time STARTS was run ./gradlew startsDiff # Types impacted by changes ./gradlew startsImpacted # Tests affected by the most recent changes ./gradlew startsSelect # To perform RTS using STARTS ./gradlew starts
  • 62. ● Run tests against production-like systems using docker Docker Testing plugin Ramey, Lloyd Nelson
  • 63. Docker Testing plugin ● Video: https://drive.google.com/file/d/1flSwgmg6bu1MM_TuVlPNL-Efx3rek20_/view
  • 65. Conclusion ● Gradle is a build automation system to configure, extend and customize the build process mainly for JVM languages. ● Gradle combines Ant’s power and flexibility with Maven’s life-cycle and ease of use by adopting a Groovy-based DSL for writing declarative build scripts with better concision and readability. ● Gradle provides outstanding extensibility and customizability by supporting various plugins.