SlideShare a Scribd company logo
Gradle -‐ Build system
Jeevesh Pandey
Agenda
2
• What and Why?
• Key features of Gradle
• Project and tasks
• Using java/groovy/war/jetty plugins
• Manage dependency
• Working with multi-‐module project
What is Gradle?
3
• A general-‐purpose build automation tool. It can automate
• building
• testing
• deployment
• publishing
• generate static websites
• generate documentation
• indeed anything else
• Designed to take advantage of convention over configuration.
• Combines the power and flexibility of Ant with the dependency management and
conventions of Maven into a more effective way to build.
Why Gradle?
Combines best features from other build tools.
Image source : http://www.drdobbs.com/jvm/why-‐build-‐your-‐java-‐projects-‐with-‐gradle/240168608
Features
Image source : http://www.drdobbs.com/jvm/why-‐build-‐your-‐java-‐projects-‐with-‐gradle/240168608
Who are using?
Installation
$ gvm install gradle
$ gradle - v
$ gradle init
$ gradle tasks
Using gvm: Ubuntu
Access gradle documentation from local file system
{USER_HOME}/.gvm/gradle/current/docs/userguide/userguide.pdf
In Windows
http://bryanlor.com/blo
g/gradle-tutorial-how-i
nstall-gradle-windows
Install
Java
Gradle project
9
• It does not necessarily represent a thing to be built.
• It might represent a
• library jar
• Web-app
• distribution zip assembled from the JARs produced by other projects.
• thing to be done : deploy to staging server
Gradle Tasks
1
0
• An atomic piece of work that a build performs.
• compile classes
• create jar
• generate java doc
• publish some archive to a repository
• Each project is made up of one or more tasks
Gradle Tasks
1
0
task compile {
doLast {
println 'compiling source'
}
}
task compileTest(dependsOn: compile) {
doLast {
println 'compiling unit tests'
}
}
task test(dependsOn: [compile, compileTest]) {
doLast {
println 'running unit tests'
}
}
task dist(dependsOn: [compile, test]) {
doLast {
println 'building the distribution'
}
}
> gradle dist test
:compile
compiling source
:compileTest
compiling unit tests
:test
running unit tests
:dist
building the distribution
BUILD SUCCESSFUL
Total time: 1 secs
> gradle dist -x test
:compile
compiling source
:dist
building the distribution
BUILD SUCCESSFUL
Total time: 1 secs
Using plugins
1
2
• Gradle core intentionally provides very little for automation.
• All of the useful features are added by plugins. e.g. java compile.
• Gradle plugins
• add new tasks (e.g. JavaCompile)
• add domain objects (e.g. SourceSet)
• add conventions (e.g. Java source is located at src/main/java)
• extends core objects and objects from other plugins
• Plugin portal : http://plugins.gradle.org/
Applying plugins
1
3
Script plugins
Binary plugins
Using plugins DSL
//from a script on the local filesystem or at a remote location.
apply from: 'other.gradle'
//Applying a binary plugin
apply plugin: 'java'
//Version is optional
plugins {
id "com.jfrog.bintray" version "0.4.1"
}
plugins {
id 'java'
}
Using java plugin
1
4
• New/modified tasks
• clean, compileJava, classes, jar, uploadArchives,
build etc.
• Default project layout
• src/main/java
• src/main/resources
• src/test/java
• Dependency configurations
• compile, runtime, testCompile, archives etc.
• Convention properties
• sourceSets,sourceCompatibility, archivesBaseName
etc.
Changing project layout for java plugin
1
5
apply plugin: 'java'
sourceSets {
main {
java {
srcDirs = ['source/main/java']
}
}
test {
java {
srcDirs = ['source/test/java']
}
}
Configure jar manifest
apply plugin: 'java'
sourceCompatibility = 1.5
//controls jar file name
version = '1.0-‐snapshot'
archivesBaseName="sample-‐java"
//self executable jar
jar {
manifest {
attributes("Main-‐Class": "com.manifest.Application", "Implementation-‐Version":
version)
}
}
Dependency management
apply plugin: 'java'
repositories {
//mavenLocal()
mavenCentral()
//maven { url "http://repo.mycompany.com/maven2"}
//flatDir { dirs 'lib1', 'lib2'}
}
dependencies {
compile "org.quartz-‐scheduler:quartz:2.1.5"
testCompile group: 'junit', name: 'junit', version: '4.11'
compile project(':shared') //project dependency
runtime files('libs/a.jar', 'libs/b.jar') //file dependency
}
Using war and jetty plugin
apply plugin: "war" //gradle assemble
//apply plugin: "jetty" //gradle jettyRun
version = "1.0.0"
archivesBaseName = "multi-‐web"
repositories {
mavenCentral()
}
dependencies {
compile project(":utils")
compile "javax.servlet:servlet-‐api:2.5"
}
Working with multi-‐project
allprojects {
task hello << { task -‐>
println "I'm $task.project.name"
}
}
subprojects {
task onlySubProjectTask << { task -‐>
println "I'm $task.project.name"
}
apply plugin: "java" repositories {
mavenCentral()
}
}
task onlyMainProjectTask<< { task -‐>
println "Only Main Project Task : ${task.project.name} "
}
multi-­‐project/
|-­‐-­‐­­build.gradle
|-­‐-­‐­­settings.gradle
|-­‐-­‐­­top
| `-­‐-­‐­­build.gradle
`-­‐-­‐­­util
`-­‐-­‐­­build.gradle
rootProject.name = 'multi-‐project'
include 'util', 'top'
settings.gradle
build.gradle
Q/A
20
Thank you.
21
References
22
http://www.gradle.org/docs/current/userguide/userguide_single.html
http://www.gradle.org/docs/current/userguide/java_plugin.html
http://www.gradle.org/docs/current/userguide/groovy_plugin.html
http://plugins.gradle.org/
http://mrhaki.blogspot.in/2010/09/gradle-goodness-run-java-application.html
http://mrhaki.blogspot.in/2009/11/using-gradle-for-mixed-java-and-groovy.html
http://rominirani.com/2014/07/28/gradle-tutorial-part-1-installation-setup/
http://rominirani.com/2014/07/28/gradle-tutorial-part-2-java-projects/
http://rominirani.com/2014/07/29/gradle-tutorial-part-3-multiple-java-projects/
http://rominirani.com/2014/08/12/gradle-tutorial-part-4-java-web-applications/
http://grails.github.io/grails-gradle-plugin/docs/manual/guide/introduction.html
http://www.drdobbs.com/jvm/why-build-your-java-projects-with-gradle/240168608
http://en.wikipedia.org/wiki/List_of_build_automation_software http://pygments.org/

More Related Content

PPTX
Spring boot Introduction
PDF
Creating Modular Test-Driven SPAs with Spring and AngularJS
PPTX
Faster java ee builds with gradle [con4921]
PPTX
Dropwizard Internals
PPTX
Preparing for java 9 modules upload
PDF
REST APIs with Spring
PPTX
Node.js Development with Apache NetBeans
PPTX
Faster Java EE Builds with Gradle
Spring boot Introduction
Creating Modular Test-Driven SPAs with Spring and AngularJS
Faster java ee builds with gradle [con4921]
Dropwizard Internals
Preparing for java 9 modules upload
REST APIs with Spring
Node.js Development with Apache NetBeans
Faster Java EE Builds with Gradle

What's hot (20)

PDF
The Spring Update
PDF
Introduction to Spring Boot!
PPTX
04 integrate entityframework
PPTX
Why jakarta ee matters (ConFoo 2021)
PPTX
06 integrate elasticsearch
PPTX
Batching and Java EE (jdk.io)
PDF
Ajug - The Spring Update
PPTX
03 integrate webapisignalr
PPT
Spring Boot in Action
PDF
COScheduler
PDF
the Spring 4 update
PPTX
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
PPTX
Spring Projects Infrastructure
PPTX
Don't Wait! Develop Responsive Applications with Java EE7 Instead
PDF
Scala play-framework
PDF
Apache Cayenne for WO Devs
PDF
Deployment of WebObjects applications on FreeBSD
KEY
Using ActiveObjects in Atlassian Plugins
PDF
Play Framework and Activator
PPTX
Powershell For Developers
The Spring Update
Introduction to Spring Boot!
04 integrate entityframework
Why jakarta ee matters (ConFoo 2021)
06 integrate elasticsearch
Batching and Java EE (jdk.io)
Ajug - The Spring Update
03 integrate webapisignalr
Spring Boot in Action
COScheduler
the Spring 4 update
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
Spring Projects Infrastructure
Don't Wait! Develop Responsive Applications with Java EE7 Instead
Scala play-framework
Apache Cayenne for WO Devs
Deployment of WebObjects applications on FreeBSD
Using ActiveObjects in Atlassian Plugins
Play Framework and Activator
Powershell For Developers
Ad

Viewers also liked (20)

PPT
Java persistence api
PPTX
JPA For Beginner's
PDF
Spring Data Jpa
PPTX
Spring.Boot up your development
PDF
REST API Best (Recommended) Practices
PPT
Spring + JPA + DAO Step by Step
PPTX
Introduction to spring boot
PPTX
Spring 4. Part 1 - IoC, AOP
ODP
Java Persistence API
PDF
20160523 hibernate persistence_framework_and_orm
PPTX
Spring Boot Update
PPTX
Cassandra for mission critical data
PDF
Java persistence api 2.1
PDF
Second Level Cache in JPA Explained
PDF
DBM專案環境建置
PPTX
Get the Most out of Testing with Spring 4.2
PDF
JPA - Beyond copy-paste
PDF
Google Web Toolkit: a case study
PDF
Introduction To Spring
Java persistence api
JPA For Beginner's
Spring Data Jpa
Spring.Boot up your development
REST API Best (Recommended) Practices
Spring + JPA + DAO Step by Step
Introduction to spring boot
Spring 4. Part 1 - IoC, AOP
Java Persistence API
20160523 hibernate persistence_framework_and_orm
Spring Boot Update
Cassandra for mission critical data
Java persistence api 2.1
Second Level Cache in JPA Explained
DBM專案環境建置
Get the Most out of Testing with Spring 4.2
JPA - Beyond copy-paste
Google Web Toolkit: a case study
Introduction To Spring
Ad

Similar to Gradle - Build System (20)

PDF
Gradle - Build system evolved
PPTX
Gradle,the new build system for android
PDF
Make Your Build Great Again (DroidConSF 2017)
PPTX
Gradle 2.Write once, builde everywhere
PDF
Android gradle-build-system-overview
PDF
Gradle - the Enterprise Automation Tool
PPTX
Gradle 2.breaking stereotypes.
PPTX
Сергей Моренец: "Gradle. Write once, build everywhere"
PDF
Keeping your build tool updated in a multi repository world
PDF
Introduction to gradle
PPTX
Faster Java EE Builds with Gradle
PPTX
Gradle : An introduction
PPTX
Gradle.Enemy at the gates
PPTX
PDF
What's new in Gradle 4.0
PPTX
Gradle 2.Breaking stereotypes
PPTX
Grails Spring Boot
PPT
An introduction to maven gradle and sbt
PDF
Intelligent Projects with Maven - DevFest Istanbul
PPTX
Exploring the power of Gradle in android studio - Basics & Beyond
Gradle - Build system evolved
Gradle,the new build system for android
Make Your Build Great Again (DroidConSF 2017)
Gradle 2.Write once, builde everywhere
Android gradle-build-system-overview
Gradle - the Enterprise Automation Tool
Gradle 2.breaking stereotypes.
Сергей Моренец: "Gradle. Write once, build everywhere"
Keeping your build tool updated in a multi repository world
Introduction to gradle
Faster Java EE Builds with Gradle
Gradle : An introduction
Gradle.Enemy at the gates
What's new in Gradle 4.0
Gradle 2.Breaking stereotypes
Grails Spring Boot
An introduction to maven gradle and sbt
Intelligent Projects with Maven - DevFest Istanbul
Exploring the power of Gradle in android studio - Basics & Beyond

Recently uploaded (20)

PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
composite construction of structures.pdf
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
OOP with Java - Java Introduction (Basics)
PDF
Digital Logic Computer Design lecture notes
PDF
Structs to JSON How Go Powers REST APIs.pdf
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
composite construction of structures.pdf
Strings in CPP - Strings in C++ are sequences of characters used to store and...
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
OOP with Java - Java Introduction (Basics)
Digital Logic Computer Design lecture notes
Structs to JSON How Go Powers REST APIs.pdf
Internet of Things (IOT) - A guide to understanding
Embodied AI: Ushering in the Next Era of Intelligent Systems
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
CH1 Production IntroductoryConcepts.pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx

Gradle - Build System