SlideShare a Scribd company logo
Gradle
is DSL (build domain)
build by convention
written in java but DSL is in groovy
supports dependency
multi projects builds
Highly Customizable
Ability to carry the version along with itself(gradle wrapper)
**ANT and MAVEN are in XML which makes it unmaintainable and hard to read as
size grows
Install Gradle
-use gradle.exe
-use GVM(Groovy Environment Manager) but difficult for Windows Machine
-through tasks(Recommended in actual projects)
build.gradle
tasks
dependency
plugins
Add properties to Gradle
-def keyword
-Similar to Groovy variable
-can have scope specific to Tasks by defining inside Task
-project.ext.projectVersion(makes it available across other gradle build
files which have same project)
Tasks
code that gradle will execute for us
have a lifecycle - 3 phases-intialization,configuration,execution
All tasks have :doFirst() and doLast() method
have actions and it has the code that would be executed
once task is defined we can append
Tasks Initalization
task Task1{
description "This is task1"
}
Tasks Configuration(Dependecy management happens in this phase)
-Task6.dependsOn Task5
or
task Task6 {
dependsOn Task5
}
-tasks dependency is decided in the configuration phase
Tasks Execution
-task Task6{
doFirst(){
println ("Doing First")
}
doLast(){
println ("Doing Last")
}
}
Dependency management,3 ways
-mustRunAfter - build fails for circular dependencies
-shouldRunAfter - ignore circular depencies
-finalizedBy - task1.finalizedBy task2 (task2 will always run after
task1)
**dependsOn vs these 3 ways[if tasks are not linked,only the specified task
runs]
Typed Tasks
-For reusablity use types tasks. eg-copy task
-Built-in tasks are provided by Gradle(eg Wrapper,copy)
Building Java Projects
-apply plugin : 'java'
-SourceSets - used to define src files if we want some diff structure for
our project
sourceSets{
main{
java{
srcDir 'src/mypath/java'
}
resources{
srcDir 'src/mypath/resources'
}
}
}
-compileJava -creates the java classes
-processResources - copy task which copies any resources to classes folder
-classes - ties compileJava and processResources
-jar low level task which creates jar
-assemble - lifecycle task in plugin
Gradle Daemon
-Gradle has to relaunch a JVM
-if we use daemon it would you already running VM which saves considerable
time
- gradle --daemon build
-recommended and is useful in large builds
-Other ways
-Specify -D flag in env variable GRADLE_OPTS
-Create a properties file(gradle.properties) in gradle home dir and set
org.gradle.daemon=true
MultiProject Build
-Add top level setting.gradle - list all projects in build
-Add top level build.gradle - add all dependecy management
Dependencies
-Java Plugin introduces:
*compile
*runtime(builds on compile)
*testComiple
*testRuntime
-Dependencies are transitive
-Listing Dependencies: gradle -q dependencies , gradle -q dependencies
-configuration runtime
Repositories
-for Maven Central
repositories {
mavenCentral()
}
-for .m2 only
repositories {
mavenLocal()
}
Caching Dependencies
-Present in .gradle > caches
--refresh-dependencies flag
Testing
-default src/test/java (can be changes using sourceSets)
-default output build/classes/test
-Reports build/reports/test
-Can filter out test to be run
-Add closure filter in test. eg:
test{
filter{
includeTestsMatching '*test' // or fully qualified name of
test if no wildcard
}
}
-filter can be overriden by --tests in comand line
Wrapper
-provides a specific version of Gradle to build the project
-Adv: Gradle will be bootstrapped.(No need to install gradle before we run
build,
wrapper will check
and install gradle if not present)
-

More Related Content

PPTX
Gradle : An introduction
PDF
Gradle 3.0: Unleash the Daemon!
PDF
An Introduction to Gradle for Java Developers
PPTX
Android presentation - Gradle ++
PDF
Gradle - the Enterprise Automation Tool
PPTX
Building with Gradle
PDF
Introduction to gradle
PDF
Gradle presentation
Gradle : An introduction
Gradle 3.0: Unleash the Daemon!
An Introduction to Gradle for Java Developers
Android presentation - Gradle ++
Gradle - the Enterprise Automation Tool
Building with Gradle
Introduction to gradle
Gradle presentation

What's hot (20)

PPTX
PDF
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
PDF
Gradle - time for a new build
PDF
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
PPTX
ReactJs
PDF
Pragmatic software development in kdb+
PDF
Gradle Introduction
PDF
PDF
Gradle - Build system evolved
PPTX
Discuss about java 9 with latest features
ODP
Gradle - time for another build
PDF
High Performance Microservices with Ratpack and Spring Boot
PDF
Idiomatic Gradle Plugin Writing - GradleSummit 2016
PDF
Java 9 Modularity in Action
PDF
Basic Gradle Plugin Writing
PPSX
Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)
PDF
Introduction maven3 and gwt2.5 rc2 - Lesson 01
PDF
Gradle como alternativa a maven
ODP
Adopting Debug Adapter Protocol in Eclipse IDE: netcoredbg (.NET debugger) ca...
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
Gradle - time for a new build
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
ReactJs
Pragmatic software development in kdb+
Gradle Introduction
Gradle - Build system evolved
Discuss about java 9 with latest features
Gradle - time for another build
High Performance Microservices with Ratpack and Spring Boot
Idiomatic Gradle Plugin Writing - GradleSummit 2016
Java 9 Modularity in Action
Basic Gradle Plugin Writing
Java 9 and the impact on Maven Projects (ApacheCon Europe 2016)
Introduction maven3 and gwt2.5 rc2 - Lesson 01
Gradle como alternativa a maven
Adopting Debug Adapter Protocol in Eclipse IDE: netcoredbg (.NET debugger) ca...
Ad

Similar to Gradle notes (20)

PPTX
Gradle.Enemy at the gates
PPTX
Gradle basics
PDF
Gradleintroduction 111010130329-phpapp01
PDF
Gradle in 45min
PPTX
A brief guide to android gradle
PDF
Enter the gradle
PPT
An introduction to maven gradle and sbt
PPTX
Gradle 2.Write once, builde everywhere
PDF
Gradle - small introduction
PDF
Gradle in a Polyglot World
PDF
Gradle
PDF
Gradle For Beginners (Serbian Developer Conference 2013 english)
PPTX
Faster Java EE Builds with Gradle
PPTX
Faster Java EE Builds with Gradle
PPTX
Faster java ee builds with gradle [con4921]
PPTX
Gradle 2.breaking stereotypes.
PPTX
PPT
Groovy Maven Builds
PDF
Why gradle
PDF
Gradle in 45min - JBCN2-16 version
Gradle.Enemy at the gates
Gradle basics
Gradleintroduction 111010130329-phpapp01
Gradle in 45min
A brief guide to android gradle
Enter the gradle
An introduction to maven gradle and sbt
Gradle 2.Write once, builde everywhere
Gradle - small introduction
Gradle in a Polyglot World
Gradle
Gradle For Beginners (Serbian Developer Conference 2013 english)
Faster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
Faster java ee builds with gradle [con4921]
Gradle 2.breaking stereotypes.
Groovy Maven Builds
Why gradle
Gradle in 45min - JBCN2-16 version
Ad

Recently uploaded (20)

PPT
Mechanical Engineering MATERIALS Selection
PPTX
OOP with Java - Java Introduction (Basics)
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
Geodesy 1.pptx...............................................
PPTX
Sustainable Sites - Green Building Construction
DOCX
573137875-Attendance-Management-System-original
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
composite construction of structures.pdf
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
additive manufacturing of ss316l using mig welding
PDF
R24 SURVEYING LAB MANUAL for civil enggi
Mechanical Engineering MATERIALS Selection
OOP with Java - Java Introduction (Basics)
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Automation-in-Manufacturing-Chapter-Introduction.pdf
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Lecture Notes Electrical Wiring System Components
Geodesy 1.pptx...............................................
Sustainable Sites - Green Building Construction
573137875-Attendance-Management-System-original
CYBER-CRIMES AND SECURITY A guide to understanding
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
composite construction of structures.pdf
bas. eng. economics group 4 presentation 1.pptx
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Foundation to blockchain - A guide to Blockchain Tech
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
additive manufacturing of ss316l using mig welding
R24 SURVEYING LAB MANUAL for civil enggi

Gradle notes

  • 1. Gradle is DSL (build domain) build by convention written in java but DSL is in groovy supports dependency multi projects builds Highly Customizable Ability to carry the version along with itself(gradle wrapper) **ANT and MAVEN are in XML which makes it unmaintainable and hard to read as size grows Install Gradle -use gradle.exe -use GVM(Groovy Environment Manager) but difficult for Windows Machine -through tasks(Recommended in actual projects) build.gradle tasks dependency plugins Add properties to Gradle -def keyword -Similar to Groovy variable -can have scope specific to Tasks by defining inside Task -project.ext.projectVersion(makes it available across other gradle build files which have same project) Tasks code that gradle will execute for us have a lifecycle - 3 phases-intialization,configuration,execution All tasks have :doFirst() and doLast() method have actions and it has the code that would be executed once task is defined we can append Tasks Initalization task Task1{ description "This is task1" } Tasks Configuration(Dependecy management happens in this phase) -Task6.dependsOn Task5 or task Task6 { dependsOn Task5 } -tasks dependency is decided in the configuration phase Tasks Execution -task Task6{ doFirst(){ println ("Doing First") } doLast(){ println ("Doing Last") } } Dependency management,3 ways -mustRunAfter - build fails for circular dependencies -shouldRunAfter - ignore circular depencies
  • 2. -finalizedBy - task1.finalizedBy task2 (task2 will always run after task1) **dependsOn vs these 3 ways[if tasks are not linked,only the specified task runs] Typed Tasks -For reusablity use types tasks. eg-copy task -Built-in tasks are provided by Gradle(eg Wrapper,copy) Building Java Projects -apply plugin : 'java' -SourceSets - used to define src files if we want some diff structure for our project sourceSets{ main{ java{ srcDir 'src/mypath/java' } resources{ srcDir 'src/mypath/resources' } } } -compileJava -creates the java classes -processResources - copy task which copies any resources to classes folder -classes - ties compileJava and processResources -jar low level task which creates jar -assemble - lifecycle task in plugin Gradle Daemon -Gradle has to relaunch a JVM -if we use daemon it would you already running VM which saves considerable time - gradle --daemon build -recommended and is useful in large builds -Other ways -Specify -D flag in env variable GRADLE_OPTS -Create a properties file(gradle.properties) in gradle home dir and set org.gradle.daemon=true MultiProject Build -Add top level setting.gradle - list all projects in build -Add top level build.gradle - add all dependecy management Dependencies -Java Plugin introduces: *compile *runtime(builds on compile) *testComiple *testRuntime -Dependencies are transitive -Listing Dependencies: gradle -q dependencies , gradle -q dependencies -configuration runtime Repositories -for Maven Central repositories { mavenCentral() } -for .m2 only repositories { mavenLocal() }
  • 3. Caching Dependencies -Present in .gradle > caches --refresh-dependencies flag Testing -default src/test/java (can be changes using sourceSets) -default output build/classes/test -Reports build/reports/test -Can filter out test to be run -Add closure filter in test. eg: test{ filter{ includeTestsMatching '*test' // or fully qualified name of test if no wildcard } } -filter can be overriden by --tests in comand line Wrapper -provides a specific version of Gradle to build the project -Adv: Gradle will be bootstrapped.(No need to install gradle before we run build, wrapper will check and install gradle if not present) -