Upcoming SlideShare
Loading in...5




Introduction to build automation tool Gradle.

Introduction to build automation tool Gradle.



Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Gradle Gradle Presentation Transcript

  • Gradle v.1.0 Andrii Khaisin Provectus IT 27.07.2013
  • About me Senior Software Developer at Provectus IT for Men's Wearhouse
  • 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.
  • 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
  • Lets some practice • Projects structure • Build running • Groovy is everywhere • Tasks • Plugin usage • Repositories • Dependencies • Custom plugin
  • 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.
  • Projects structure example project/ api/ src/ build.gradle data/ src/ war/ src/ main/ test/ build.gradle settings.gradle
  • 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, ...]]
  • Groovy is everywhere • Gradle scripts are Groovy scripts • Gradle works in JVM • All Java world in your hands
  • 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"; }
  • Tasks • Task is a named piece of work • Tasks have relations between each other • Tasks creates steps by step process of project build
  • Tasks example def env; def user; task prepareEnv << { env = System.getenv(); } task prepareUser (dependsOn: 'prepareEnv') << { user = env['USER']; } task printEnv (dependsOn: 'prepareEnv') << { env.each { println it } } task printUser (dependsOn: 'prepareUser' ) << { if (user != null) { println "User: $user"; } }
  • 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
  • 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
  • Repositories repositories { mavenLocal() mavenCentral() mavenRepo name: "lib", url:"libs" mavenRepo url: "" ivy { url "" } // Any custom defined source of artifacts }
  • 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
  • Dependencies example allprojects { dependencies { compile ''commons-collections:commons-collections:3.1'' testCompile group: 'junit', name: 'junit', version: '4.+' } } project(':api') { dependencies { compile ''$wsVersion'' } } project(':server') { dependencies { runtime ''$wsVersion'' } }
  • 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
  • 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
  • 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" }
  • Gradle is • powerful • simple • compact • evolving • possible to debug Gradle is just fun!
  • That's all :)
  • Links Build tools • • • • • • •