SlideShare uma empresa Scribd logo
1 de 22
Baixar para ler offline
Gradle
Small introduction
Required knowledge
●
●
●
●
●

average java
average groovy (properties, closures, collections: lists, maps)
general knowledge of build scripts (ant, maven etc)
mad search skillz (google)
desire to learn
Groovy Lang - quick intro
●
●
●
●

lists: [1, 2, 3, 4]
maps: ['key1': 'value1', 'key2': 'value2'] --> can be used as parameters to
methods
when calling methods the parens are optional
properties: instead of using getters and setters directly you can just use the
name of the property as if it were a "normal" variable (without the "set" and
"get" prefix)
The Gradle DSL
●
●
●

a Domain Specific Language
a language designed for a specific need (such as building projects)
uses groovy
The Project
●
●
●

the most important object in the Gradle DSL
everything you need is inside the "project" variable
if you don't specify an object all the method calls are delegated to the
"project" variable
Simple example: fileTree
●
●

1.
2.
3.
4.

used for example when you want to load all the files in a directory (the "lib"
directory which contains all the jars)
TMTOWTDI: there's more than one way to do it

fileTree('lib')
fileTree('lib').include('**/*.java').exclude('**/*.cpp')
fileTree(dir: 'lib', include: '**/*.java', exclude: '**/*.cpp')
fileTree('lib') {
include '**/*.java'
exclude '**/*.cpp'
}
Implementation of fileTree
First example: fileTree('lib')
From source code: ConfigurableFileTree fileTree(Object baseDir);
The baseDir is actually a string.
Implementation of fileTree
Second example: fileTree('lib').include('**/*.java').exclude('**/*.cpp')
From source code: ConfigurableFileTree fileTree(Object baseDir);
Gradle uses here something called: fluent interface
(read more here: http://www.martinfowler.com/bliki/FluentInterface.html).
Basically this means you can chain method calls.
Probably you are wondering where are these include and exclude methods
from, hmm? Well, they are from a super interface of ConfigurableFileTree:
org.gradle.api.tasks.util.PatternFilterable.
Implementation of fileTree
Third example: fileTree(dir: 'lib', include: '**/*.java', exclude: '**/*.cpp')
From source code: ConfigurableFileTree fileTree(Map<String, ?> args);
Here, each of "dir", "include" and "exclude" are actually the keys of a map.
Behind the scenes the fileTree method will configure a ConfigurableFileTree
object.
Implementation of fileTree
Fourth example: fileTree('lib') {
include '**/*.java'
exclude '**/*.cpp'
}

From source code: ConfigurableFileTree fileTree(Object baseDir, Closure configureClosure);
There is yet another way to configure the fileTree method: using a closure.
The Simplest Gradle Script
apply plugin: "java"
This assumes that you respect the standard maven project structure:
src
|____ main
|
|____ java // here go all the source files ...
|
|
|____ test
|____ java // ... and here go all the test classes
The Simplest Gradle Script
Why does this simple script work?
Gradle:
● uses a thing called "Convention over Configuration",
● provides a number of tasks to ease the creation of a new project:
○ :compileJava
○ :processResources
○ :classes
○ :jar
○ :assemble
○ :compileTestJava
○ :processTestResources
○ :testClasses
○ :test
○ :check
○ :build
Custom tasks
task --> groovy compiler plugin:
Standard way to define a new task:

task myTaskName() {
// doing some stuff...
}
This is actually a more convenient way for the following:

task("myTaskName")

Source (StackOverflow): How to interpret Gradle DSL
Custom tasks
Gradle provides some predefined tasks which you can configure.
Example: Copy, Zip, Compile, Jar, War
task myCopyTask(type: Copy) {
from 'src/main/webapp'
into 'build/explodedWar'
}
Notice that the task receives a named parameter (a map with one entry
actually) called type.
This is similar to inheriting from a base class in the sense that now, in the
closure (the stuff between curly brackets { // stuff }) you have access to the
from and into methods. These are specific to the copy task.
doLast notation
Sometimes you need to add something to an existing task.
For example to add some stuff to the task defined in the previous slide we
would do:
task myCopyTask << {
// do something
}

This is equivalent to the following:
task myCopyTask.doLast {
// do something
}
The doLast notation is pretty common in build scripts so you'd better remember
it :)
Order must be mantained
Sometimes you need to specify that a task should run only after other tasks are
run first. For this you need to use dependsOn.

task someOtherTask() {
// do some other stuff
}
task myTask(dependsOn: someOtherTask) {
// do stuff
}
Gradle Plugins
These add new capabilities to gradle (obviously).
Here's how to add a plugin:

apply plugin: "java"
The plugins basically:
● Add tasks to the project (example compile, test)
● Preconfigure tasks with defaults
● Add dependency configurations to the project
● Add new properties and methods to existing type via extensions

There are plugins for many things such as static code analysis, new languages
(groovy), various IDE's (eclipse, idea).
The Wrapper
Gradle provides a way to build a project even without having gradle installed,
although you need to have at least the JDK installed.
Here is how to define the wrapper task:

task wrapper(type: Wrapper) {
gradleVersion = '1.3'
}
And here's how you call it from the command line:

gradle wrapper
You need to run this each time you update the gradle version variable.
Gradle will generate some files in the project's root directory: gradlew.bat
gradlew and the gradle directory.
The Wrapper
The recommended way to build the project after you generate the wrapper
files is using the gradlew.bat script which will take the same parameters as
the "normal" gradle:

gradlew build
Just be carefull to call gradlew in the project root directory
(since that's were the script is located).
Adding libraries
First: you must define a repository that tells gradle where to take the libraries
from.
Here's how to do it:

repositories {
mavenCentral()
}
mavenCentral() is the usual repository you should use.
Second: you must specify the libraries you want to use. For example, if you
want junit you need to search on MvnRepository the actual string to include:

dependencies {
testCompile 'junit:junit:+'
}
The complete script
apply plugin: 'java'
apply plugin: 'eclipse'
defaultTasks 'build', 'eclipse'
repositories {
mavenCentral()
}
dependencies {
testCompile 'junit:junit:+'
}
task wrapper(type: Wrapper) {
gradleVersion = '1.3'
}
Thanks...

Thanks for attention
and

Enjoy!

Mais conteúdo relacionado

Mais procurados

Ts archiving
Ts   archivingTs   archiving
Ts archiving
Confiz
 
Modeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based GamesModeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based Games
Ray Toal
 
iOS Multithreading
iOS MultithreadingiOS Multithreading
iOS Multithreading
Richa Jain
 
JavaScript: Patterns, Part 2
JavaScript: Patterns, Part  2JavaScript: Patterns, Part  2
JavaScript: Patterns, Part 2
Chris Farrell
 
20100712-OTcl Command -- Getting Started
20100712-OTcl Command -- Getting Started20100712-OTcl Command -- Getting Started
20100712-OTcl Command -- Getting Started
Teerawat Issariyakul
 

Mais procurados (20)

DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright
 
Ts archiving
Ts   archivingTs   archiving
Ts archiving
 
Node.js extensions in C++
Node.js extensions in C++Node.js extensions in C++
Node.js extensions in C++
 
Modeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based GamesModeling Patterns for JavaScript Browser-Based Games
Modeling Patterns for JavaScript Browser-Based Games
 
Objective-C Blocks and Grand Central Dispatch
Objective-C Blocks and Grand Central DispatchObjective-C Blocks and Grand Central Dispatch
Objective-C Blocks and Grand Central Dispatch
 
Playing the toStrings
Playing the toStringsPlaying the toStrings
Playing the toStrings
 
DaNode - A home made web server in D
DaNode - A home made web server in DDaNode - A home made web server in D
DaNode - A home made web server in D
 
Basic Packet Forwarding in NS2
Basic Packet Forwarding in NS2Basic Packet Forwarding in NS2
Basic Packet Forwarding in NS2
 
iOS Multithreading
iOS MultithreadingiOS Multithreading
iOS Multithreading
 
GCD and OperationQueue.
GCD and OperationQueue.GCD and OperationQueue.
GCD and OperationQueue.
 
NS2 Classifiers
NS2 ClassifiersNS2 Classifiers
NS2 Classifiers
 
Collections forceawakens
Collections forceawakensCollections forceawakens
Collections forceawakens
 
packet destruction in NS2
packet destruction in NS2packet destruction in NS2
packet destruction in NS2
 
Best practices in Java
Best practices in JavaBest practices in Java
Best practices in Java
 
JavaScript: Patterns, Part 2
JavaScript: Patterns, Part  2JavaScript: Patterns, Part  2
JavaScript: Patterns, Part 2
 
Testing con spock
Testing con spockTesting con spock
Testing con spock
 
Complete Java Course
Complete Java CourseComplete Java Course
Complete Java Course
 
NS2 Shadow Object Construction
NS2 Shadow Object ConstructionNS2 Shadow Object Construction
NS2 Shadow Object Construction
 
NS2 Object Construction
NS2 Object ConstructionNS2 Object Construction
NS2 Object Construction
 
20100712-OTcl Command -- Getting Started
20100712-OTcl Command -- Getting Started20100712-OTcl Command -- Getting Started
20100712-OTcl Command -- Getting Started
 

Destaque

Gradle - time for a new build
Gradle - time for a new buildGradle - time for a new build
Gradle - time for a new build
Igor Khotin
 

Destaque (8)

Gradle 101
Gradle 101Gradle 101
Gradle 101
 
Gradle - the Enterprise Automation Tool
Gradle  - the Enterprise Automation ToolGradle  - the Enterprise Automation Tool
Gradle - the Enterprise Automation Tool
 
Gradle : An introduction
Gradle : An introduction Gradle : An introduction
Gradle : An introduction
 
Gradle - time for a new build
Gradle - time for a new buildGradle - time for a new build
Gradle - time for a new build
 
An Introduction to Gradle for Java Developers
An Introduction to Gradle for Java DevelopersAn Introduction to Gradle for Java Developers
An Introduction to Gradle for Java Developers
 
Gradle
GradleGradle
Gradle
 
Gradle
GradleGradle
Gradle
 
Gradle by Example
Gradle by ExampleGradle by Example
Gradle by Example
 

Semelhante a Gradle - small introduction

10 Cool Facts about Gradle
10 Cool Facts about Gradle10 Cool Facts about Gradle
10 Cool Facts about Gradle
Evgeny Goldin
 
Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01
Tino Isnich
 

Semelhante a Gradle - small introduction (20)

Idiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingIdiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin Writing
 
10 Cool Facts about Gradle
10 Cool Facts about Gradle10 Cool Facts about Gradle
10 Cool Facts about Gradle
 
Android presentation - Gradle ++
Android presentation - Gradle ++Android presentation - Gradle ++
Android presentation - Gradle ++
 
GradleFX
GradleFXGradleFX
GradleFX
 
Advanced Node.JS Meetup
Advanced Node.JS MeetupAdvanced Node.JS Meetup
Advanced Node.JS Meetup
 
Gradle in 45min
Gradle in 45minGradle in 45min
Gradle in 45min
 
Gradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 versionGradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 version
 
Improving your Gradle builds
Improving your Gradle buildsImproving your Gradle builds
Improving your Gradle builds
 
Idiomatic gradle plugin writing
Idiomatic gradle plugin writingIdiomatic gradle plugin writing
Idiomatic gradle plugin writing
 
Global objects in Node.pdf
Global objects in Node.pdfGlobal objects in Node.pdf
Global objects in Node.pdf
 
Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01
 
Basic Gradle Plugin Writing
Basic Gradle Plugin WritingBasic Gradle Plugin Writing
Basic Gradle Plugin Writing
 
OpenCms Days 2012 - Developing OpenCms with Gradle
OpenCms Days 2012 - Developing OpenCms with GradleOpenCms Days 2012 - Developing OpenCms with Gradle
OpenCms Days 2012 - Developing OpenCms with Gradle
 
Idiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingIdiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin Writing
 
Anatomy of a Gradle plugin
Anatomy of a Gradle pluginAnatomy of a Gradle plugin
Anatomy of a Gradle plugin
 
Idiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingIdiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin Writing
 
Gradle in a Polyglot World
Gradle in a Polyglot WorldGradle in a Polyglot World
Gradle in a Polyglot World
 
Explore the Rake Gem
Explore the Rake GemExplore the Rake Gem
Explore the Rake Gem
 
Little Did He Know ...
Little Did He Know ...Little Did He Know ...
Little Did He Know ...
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

Gradle - small introduction

  • 2. Required knowledge ● ● ● ● ● average java average groovy (properties, closures, collections: lists, maps) general knowledge of build scripts (ant, maven etc) mad search skillz (google) desire to learn
  • 3. Groovy Lang - quick intro ● ● ● ● lists: [1, 2, 3, 4] maps: ['key1': 'value1', 'key2': 'value2'] --> can be used as parameters to methods when calling methods the parens are optional properties: instead of using getters and setters directly you can just use the name of the property as if it were a "normal" variable (without the "set" and "get" prefix)
  • 4. The Gradle DSL ● ● ● a Domain Specific Language a language designed for a specific need (such as building projects) uses groovy
  • 5. The Project ● ● ● the most important object in the Gradle DSL everything you need is inside the "project" variable if you don't specify an object all the method calls are delegated to the "project" variable
  • 6. Simple example: fileTree ● ● 1. 2. 3. 4. used for example when you want to load all the files in a directory (the "lib" directory which contains all the jars) TMTOWTDI: there's more than one way to do it fileTree('lib') fileTree('lib').include('**/*.java').exclude('**/*.cpp') fileTree(dir: 'lib', include: '**/*.java', exclude: '**/*.cpp') fileTree('lib') { include '**/*.java' exclude '**/*.cpp' }
  • 7. Implementation of fileTree First example: fileTree('lib') From source code: ConfigurableFileTree fileTree(Object baseDir); The baseDir is actually a string.
  • 8. Implementation of fileTree Second example: fileTree('lib').include('**/*.java').exclude('**/*.cpp') From source code: ConfigurableFileTree fileTree(Object baseDir); Gradle uses here something called: fluent interface (read more here: http://www.martinfowler.com/bliki/FluentInterface.html). Basically this means you can chain method calls. Probably you are wondering where are these include and exclude methods from, hmm? Well, they are from a super interface of ConfigurableFileTree: org.gradle.api.tasks.util.PatternFilterable.
  • 9. Implementation of fileTree Third example: fileTree(dir: 'lib', include: '**/*.java', exclude: '**/*.cpp') From source code: ConfigurableFileTree fileTree(Map<String, ?> args); Here, each of "dir", "include" and "exclude" are actually the keys of a map. Behind the scenes the fileTree method will configure a ConfigurableFileTree object.
  • 10. Implementation of fileTree Fourth example: fileTree('lib') { include '**/*.java' exclude '**/*.cpp' } From source code: ConfigurableFileTree fileTree(Object baseDir, Closure configureClosure); There is yet another way to configure the fileTree method: using a closure.
  • 11. The Simplest Gradle Script apply plugin: "java" This assumes that you respect the standard maven project structure: src |____ main | |____ java // here go all the source files ... | | |____ test |____ java // ... and here go all the test classes
  • 12. The Simplest Gradle Script Why does this simple script work? Gradle: ● uses a thing called "Convention over Configuration", ● provides a number of tasks to ease the creation of a new project: ○ :compileJava ○ :processResources ○ :classes ○ :jar ○ :assemble ○ :compileTestJava ○ :processTestResources ○ :testClasses ○ :test ○ :check ○ :build
  • 13. Custom tasks task --> groovy compiler plugin: Standard way to define a new task: task myTaskName() { // doing some stuff... } This is actually a more convenient way for the following: task("myTaskName") Source (StackOverflow): How to interpret Gradle DSL
  • 14. Custom tasks Gradle provides some predefined tasks which you can configure. Example: Copy, Zip, Compile, Jar, War task myCopyTask(type: Copy) { from 'src/main/webapp' into 'build/explodedWar' } Notice that the task receives a named parameter (a map with one entry actually) called type. This is similar to inheriting from a base class in the sense that now, in the closure (the stuff between curly brackets { // stuff }) you have access to the from and into methods. These are specific to the copy task.
  • 15. doLast notation Sometimes you need to add something to an existing task. For example to add some stuff to the task defined in the previous slide we would do: task myCopyTask << { // do something } This is equivalent to the following: task myCopyTask.doLast { // do something } The doLast notation is pretty common in build scripts so you'd better remember it :)
  • 16. Order must be mantained Sometimes you need to specify that a task should run only after other tasks are run first. For this you need to use dependsOn. task someOtherTask() { // do some other stuff } task myTask(dependsOn: someOtherTask) { // do stuff }
  • 17. Gradle Plugins These add new capabilities to gradle (obviously). Here's how to add a plugin: apply plugin: "java" The plugins basically: ● Add tasks to the project (example compile, test) ● Preconfigure tasks with defaults ● Add dependency configurations to the project ● Add new properties and methods to existing type via extensions There are plugins for many things such as static code analysis, new languages (groovy), various IDE's (eclipse, idea).
  • 18. The Wrapper Gradle provides a way to build a project even without having gradle installed, although you need to have at least the JDK installed. Here is how to define the wrapper task: task wrapper(type: Wrapper) { gradleVersion = '1.3' } And here's how you call it from the command line: gradle wrapper You need to run this each time you update the gradle version variable. Gradle will generate some files in the project's root directory: gradlew.bat gradlew and the gradle directory.
  • 19. The Wrapper The recommended way to build the project after you generate the wrapper files is using the gradlew.bat script which will take the same parameters as the "normal" gradle: gradlew build Just be carefull to call gradlew in the project root directory (since that's were the script is located).
  • 20. Adding libraries First: you must define a repository that tells gradle where to take the libraries from. Here's how to do it: repositories { mavenCentral() } mavenCentral() is the usual repository you should use. Second: you must specify the libraries you want to use. For example, if you want junit you need to search on MvnRepository the actual string to include: dependencies { testCompile 'junit:junit:+' }
  • 21. The complete script apply plugin: 'java' apply plugin: 'eclipse' defaultTasks 'build', 'eclipse' repositories { mavenCentral() } dependencies { testCompile 'junit:junit:+' } task wrapper(type: Wrapper) { gradleVersion = '1.3' }