Gradle is an open source build automation system that builds upon the concepts of Apache Ant and Apache Maven and introduces a Groovy-based domain-specific language (DSL) instead of the XML form used by Apache Maven for declaring the project configuration.
2. Topics
1. What is Build Tool?
2. Getting Started With Gradle
3. Building JVM Projects
3. What is Build Tool?
● Build tools are programs that automate the creation of executable
applications from source code.
● Building incorporates compiling, linking and packaging the code into a usable
or executable form.
4. What is Gradle?
Gradle is an open source build automation system that builds upon the concepts
of Apache Ant and Apache Maven and introduces a Groovy-based
domain-specific language (DSL) instead of the XML form used by Apache Maven
for declaring the project configuration.
8. Core Components
● Projects: A project is typically some software you want to build.
● Tasks: Tasks are actions needed to build the projectTasks are actions
needed to build the project
● Build scripts: The build script is typically called build.gradle and is
normally located in the root directory of the project
9. Gradle Tasks
● A task might be compiling some classes, creating a JAR, generating
Javadoc, or publishing some archives to a repository
● In simple words, a project is made up of different tasks.
10. Task Dependencies & Ordering
● dependsOn creates an execution dependency
● All execution dependencies of a task must also be executed and
completed before the task
11. Task Dependencies & Ordering
● finalizedBy creates a finalization dependency
● The finalizer task is added if the finalized task is present in the task graph
13. Locating Dependencies
● Gradle supplies some default repositories to search:
jcenter, mavenCentral, mavenLocal
● Can also look at custom maven,
ivy, and file system paths
14. Extra Properties
Extra properties extensions allow new properties to be added to existing domain
objects. They act like maps, allowing the storage of arbitrary key/value pairs.
16. Plugins
● A plugin is a set of tasks
● A gradle plugin is library of code that, when loaded by Gradle build script,
adds new functionality and capabilities to the build system.
Plugins can −
● Extend the basic Gradle model (e.g. add new DSL elements that can be
configured).
● Configure the project according to conversions (e.g. add new tasks or
configure sensible defaults).
● Apply specific configuration
17. Types of Plugin
● Script Plugins
Script plugins can be applied from a script on the local filesystem or at a
remote location. Filesystem locations are relative to the project directory
apply from: 'other.gradle'
● Binary Plugins
Each plugin is identified by a plugin id. Some core plugins use short names to
apply it
apply plugin: JavaPlugin
19. Publishing Artifacts
● The files the project provides to the outside world. This might be a library
or a ZIP distribution or any other file. A project can publish as many
artifacts as it wants.
● The artifacts could be published to either local system or repository url
20. Gradle Wrapper
● When you use the Gradle Wrapper, you embed some intelligence into
your project. When some one runs the build for the first time, they run
“gradlew” which is an automatically generated shell script (or Batch script
on Windows) designed to download Gradle. As the build manager, you
generate this file from your Gradle build so that you don't have to write
instructions for installing Gradle.
● The Gradle Wrapper takes build automation to another level - Gradle can,
effectively, install itself.
21. Install Gradle Wrapper
● Install the Wrapper into your project by running the wrapper task. (This
task is always available, even if you don't add it to your build)
gradle wrapper --gradle-version 2.0
Or
task wrapper(type: Wrapper) {
gradleVersion = '2.0'
}