3. Gradle in a few words
• Gradle is task oriented build tool.
• Gradle has a set of default plugins which
define conventions and standard life cycle of
project build.
• Gradle build scripts are Groovy scripts which
customize default workflow for your needs.
• Gradle works well for Java projects and for
non Java projects as well.
4. What we need from a build tool
• Ability to create and support build scripts
• Ability to define projects hierarchy for multi
module build
• Ability to manage project dependencies
• Ability to implement custom build logic
• Ability to extend available plugins
• Ability to develop new own plugins
• Ability to support build configurations
5. Lets some practice
• Projects structure
• Build running
• Groovy is everywhere
• Tasks
• Plugin usage
• Repositories
• Dependencies
• Custom plugin
6. Projects structure
• Project object model
• Convention over configuration
• Customize project model with build.gradle
• Split big scripts into parts
• Put submodule related script into separate
file or keep everything in one file.
8. Build running
Gradle Installing approaches
• Locally installed Gradle distribution
• Gradle Wrapper - Keep it with you project
and wrapper solve all other tasks as Gradle
version, downloading Gradle and etc.
• GVM - Groovy enVironment Manager
Gradle launch
gradle <params> [task1, [task2, taks3, ...]]
9. Groovy is everywhere
• Gradle scripts are Groovy scripts
• Gradle works in JVM
• All Java world in your hands
10. Groovy is everywhere example
// Somewhere in build.gradle
def env = System.getenv();
System.getenv().each {
println it
}
def user = env['USER'];
if (user != null) {
println "User: $user";
}
11. Tasks
• Task is a named piece of work
• Tasks have relations between each other
• Tasks creates steps by step process of
project build
13. Plugins usage
1. Declare that certain plugin will be used
apply plugin: 'java' – adds Java lifecircle
2. Configure properties of this plugin
3. Launch task defined by this plugin
14. Java plugin and its tasks
Java plugin define set of tasks and dependencies between
the. In the way there is create lifecircle similar to lifecircle
available in Maven
16. Dependencies
• Dependency is described by group, name, version and
other optional attributes
• Dependency types are configurable by plugins
• Java plugin adds compile, runtime, testCompile,
testRuntime
• Gradle support dependency version ranges
• transitive dependency management
18. Custom plugins and tasks
There are places where custom plugins could
be stored:
• build.gradle
• apply from: 'other.gradle'
• buildSrc folder which is automatically used
as a sources of additional scripts
• Remotelocal repositories
19. Custom plugins - buildSrc
buildSrc/ - Additional module with build script sources
src/
main/
groovy/
Wsdl2JavaPlugin.groovy
test/
build.gradle - more configuration if needed
api/
data/
server/
build.gradle
settings.gradle
20. Custom plugins - wsdl2java
def class Wsdl2JavaPlugin implements Plugin<Project> {
void apply(Project project) {
// Take configuration of WSDL file path
// Inject task in build life cycle
project.tasks.processResources.dependsOn Wsdl2JavaTask
// Generate sources and add theirs folder to Sources Set
}
}
// Then somewhere in the project
project(':api') {
apply plugin: 'wsdl2java'
wsdl2java src:"api/src/main/resources/wsdl/Service.wsdl"
}
21. Gradle is
• powerful
• simple
• compact
• evolving
• possible to debug
Gradle is just fun!