SlideShare una empresa de Scribd logo
1 de 39
Descargar para leer sin conexión
Introduction to Gradle
Andrey Adamovich
Aestas/IT
What is Gradle?
   Gradle is a general purpose build system
   It comes with a rich build description
    language (DSL) based on Groovy
   It supports ”build-by-convention” principle
   But it is very flexible and extensible
   It has built-in plug-ins for Java, Groovy,
    Scala, Web, OSGi
   It derives all the best and integrates well
    with Ivy, Ant and Maven
What’s in this presentation?
 Overview
 Basic features & principles
 Files and file collections
 Dependencies
 Multiple projects
 Plug-ins
 Reading material
 Questions
OVERVIEW
Gradle features I
 Declarative builds and build-by-
  convention
 Language for dependency based
  programming and many ways to
  manage dependencies
 Groovy as a base language allows
  imperative programming
Gradle features II
 Deep and rich API for managing
  projects, tasks, dependency
  artefacts and much more.
 State of the art support for multi-
  project builds
 Ease of integration and migration.
  Ant, Maven, Ivy are supported out-
  of-the-box
 Free and open source
Advanced features
 Parallel unit test execution
 Dependency build
 Incremental build support
 Dynamic tasks and task rules
 Gradle daemon
Who uses Gradle?
   Hibernate               Canoo
   Grails                  Carrier
   Groovy                  FCC
   Spring Integration      Zeppelin
   Spring Security         GPars
   Griffon                 Spock
   Gaelyk                  Aluminum
   Qi4j                    Gant
BASIC FEATURES &
PRINCIPLES
Hello, Gradle!
build.gradle:
task hello << {
  println ’Hello, World'
}            >gradle hello
                :hello
                Hello, World!

                BUILD SUCCESSFUL

                Total time: 2.401 secs


build.gradle:
task hello << {
  print ’Hello, '
}

task world(dependsOn: hello) << {
  println ’World!'
}             >gradle -q hello world
                Hello, World!

                >gradle -q world
                Hello, World!
Task configuration & execution
task hello

message = "What's up?"

hello {
  println "Configuring hello task."
  message = 'Hello, World!'
}

hello << {
  println message
                              >gradle hello
}                             Configuring hello task.
                              :hello
                              Hello, World!
hello << {                    What's up?
  println project.message
                              BUILD SUCCESSFUL
}
                              Total time: 1.958 secs
Gradle is Groovy, Groovy is Java
Java:

import java.io.File;
…
String parentDir = new File(”test.txt”)
                     .getAbsoluteFile()
                     .getParentPath();


Groovy:
def parentDir = new File(”test.txt”).absoluteFile.parentPath



Gradle:
parentDir = file(”test.txt”).absoluteFile.parentPath
Building Java project
apply plugin: 'java'


                       >gradle clean build
                       :clean
                       :compileJava
                       :processResources UP-TO-DATE
                       :classes
                       :jar
                       :assemble
                       :compileTestJava UP-TO-DATE
                       :processTestResources UP-TO-DATE
                       :testClasses UP-TO-DATE
                       :test
                       :check
                       :build

                       BUILD SUCCESSFUL

                       Total time: 7.6 secs
Java plug-in tasks
 compileJava         processResources                    clean


                            classes                     javadoc


compileTestJava    processTestResources                   jar


                          testClasses


                             test                      uploadArchives


                  check                     assemble



                                    build
Extending tasks
test {
  systemProperties ("net.sourceforge.cobertura.datafile": cobSerFile)
  cobSerFile = "${project.buildDir}/cobertura.ser"
}

test.doFirst {
  ant {
    delete(file: cobSerFile, failonerror: false)
    'cobertura-instrument'(datafile: cobSerFile) {
        fileset(dir: "${sourceSets.main.classesDir}", includes: "**/*.class") }
    }
  }
}

test.doLast {
  ant.'cobertura-report'(
        destdir: "${project.buildDirName}/test-results",
        format: 'xml',
        srcdir: "src/main/java",
        datafile: cobSerFile)
}
Ant is a first-class citizen

   All Ant tasks and types can be used
    inside Gradle script using Groovy
    syntax

   Whole Ant build script can be
    imported into Gradle and its targets
    can be called
Ant usage examples I
task hello << {
  String greeting = "hello from Ant"
  ant.echo(message: greeting)
}


task list << {
  def path = ant.path {
    fileset(dir: 'libs', includes: '*.jar')
  }
  path.list().each {
    println it
  }
}


task zip << {
  ant.zip(destfile: 'archive.zip') {
    fileset(dir: 'src') {
      include(name: '**.xml')
      exclude(name: '**.java')
    }
  }
}
Ant usage examples II
ant.taskdef(resource: 'checkstyletask.properties') {
  classpath {
    fileset(dir: 'libs/checkstyle', includes: '*.jar')
  }
}

ant.checkstyle(config: 'src/tools/sun_checks.xml') {
  fileset(dir: 'src')
}




<project>
  <target name="hello">
     <echo>Hello, from Ant</echo>
  </target>
</project>                                   >gradle hello
                                             :hello
                                             [ant:echo] Hello, from Ant

ant.importBuild 'build.xml'                  BUILD SUCCESSFUL

                                             Total time: 7.898 secs
Overriding conventions
version = 1.0
group = ’org.gradletutorials’


version = "1.0-${new Date().format('yyyyMMdd')}"


task release(dependsOn: assemble) << {
  println 'We release now'
}

build.taskGraph.whenReady { taskGraph ->
  if (taskGraph.hasTask(':release')) {
    version = '1.0’
  } else {
    version = '1.0-SNAPSHOT’
  }
}



sourceSets.main.java.srcDirs += ["src/generated/java"]
sourceSets.main.resources.srcDirs += ["src/generated/resources"]
More examples
 Many source directory sets per
  project without a need of a plug-in
 Different dependencies per source
  directory
 Even different JDK per source
  directory
 Many artifacts per project
FILES AND FILE
COLLECTIONS
Referencing files & file collections
Groovy-like syntax:
// Using a relative path
File configFile = file('src/config.xml')

Create a file collection from a bunch of files:
FileCollection collection = files(
      'src/file1.txt',
      new File('src/file2.txt'),
      ['src/file3.txt', 'src/file4.txt'])

Create a files collection by referencing project properties:
collection = files { srcDir.listFiles() }

Operations on collections:
def union = collection + files('src/file4.txt')
def different = collection - files('src/file3.txt')}
Using file collections as input
Many objects in Gradle have properties, which accept a set of
input files. For example, the compile task has a source property,
which defines the source files to compile. You can set the value
of this property using any of the types supported by the files()
method:
// Use a File object to specify the source directory.
compile {
  source = file('src/main/java')
}

// Using a closure to specify the source files.
compile {
  source = {
    // Use the contents of each zip file in the src dir.
    file('src')
      .listFiles()
      .findAll { it.name.endsWith('.zip') }
      .collect { zipTree(it) }
    }
  }
}1
Copying files
Using Ant integration:
ant.copy(todir: 'javadoc') {
  fileset(dir: 'build/docs')
}


Using Gradle task type:

task copyTask(type: Copy) {
  from 'src/main/webapp‘
  into 'build/explodedWar‘
  include '**/*.jsp‘
  exclude { details ->
    details.file.name.endsWith('.html') &&
    details.file.text.contains('staging')
  }
}
DEPENDENCY
MANAGEMENT
Repository configuration
repositories {
  mavenCentral()
}


repositories {
  mavenCentral name: 'single-jar-repo', urls: "http://repo.mycompany.com/jars"
  mavenCentral name: 'multi-jar-repos', urls:
    ["http://repo.mycompany.com/jars1", "http://repo.mycompany.com/jars1"]
}


repositories {
  flatDir name: 'localRepository',
  dirs: 'lib' flatDir dirs: ['lib1', 'lib2']
}


repositories {
  add(new org.apache.ivy.plugins.resolver.FileSystemResolver()) {
    name = 'localRepository'
    latestStrategy = new org.apache.ivy.plugins.latest.LatestTimeStrategy()
    addArtifactPattern(libDir +
      '/[organization]/[artifact]/[ext]s/[artifact]-[revision].[ext]')
  }
}
Referencing dependencies
dependencies {
  runtime files('libs/a.jar', 'libs/b.jar')
  runtime fileTree(dir: 'libs', includes: ['*.jar'])
}

dependencies {
  compile 'org.springframework:spring-webmvc:3.0.0.RELEASE'
  testCompile 'org.springframework:spring-test:3.0.0.RELEASE'
  testCompile 'junit:junit:4.7'
}


dependencies {
  runtime group: 'org.springframework', name: 'spring-core', version: '2.5'
  runtime 'org.springframework:spring-core:2.5',
          'org.springframework:spring-aop:2.5
}


List groovy = ["org.codehaus.groovy:groovy-all:1.5.4@jar",
               "commons-cli:commons-cli:1.0@jar",
               "org.apache.ant:ant:1.7.0@jar"]
List hibernate = ['org.hibernate:hibernate:3.0.5@jar',
                  'somegroup:someorg:1.0@jar']

dependencies {
  runtime groovy, hibernate
}
Transitive dependencies
configurations.compile.transitive = true

dependencies {
  compile 'org.springframework:spring-webmvc:3.0.0.RC2'
  runtime 'org.hibernate:hibernate:3.0.5'
}




dependencies {
  compile 'org.springframework:spring-webmvc:3.0.0.RC2'
  runtime('org.hibernate:hibernate:3.0.5') {
    transitive = true
  }
}
MULTI-PROJECT BUILDS
Directories & settings.gradle
settings.gradle:

include 'shared', 'api', ':service:service1', ':service:service2'




                                 You can have only one build file
                                  for the whole multi-project build
                                 All properties, settings, plug-ins,
                                  dependencies are derived without
                                  a need to duplicate information
                                 You can override almost all
                                  behaviour in child builds
All or something
allprojects {
  task build << {
    println "Building project: " + project.name
  }
}                                   >gradle build
                                     :build
subprojects {                        Building project: 90-multi-project
  task prebuild << {                 :api:prebuild
    println "It is subproject!"      It is subproject!
                                     :api:build
  }                                  Building project: api
  build.dependsOn prebuild           :service:prebuild
}                                    It is subproject!
                                     :service:build
                                     Building project: service
                                     :shared:prebuild
                                     It is subproject!
                                     :shared:build
                                     Building project: shared
                                     :service:service1:prebuild
                                     It is subproject!
                                     :service:service1:build
                                     Building project: service1
                                     :service:service2:prebuild
                                     It is subproject!
                                     :service:service2:build
                                     Building project: service2

                                     BUILD SUCCESSFUL

                                     Total time: 9.684 secs
Inter-project dependencies
subprojects {
  apply plugin: 'java'
  if (project.name.matches('^.*serviced+$')) {
    dependencies {
                                  >gradle clean build
      compile project(':api')
                                  :api:clean
      compile project(':shared') :service:clean
    }                             :shared:clean
  }                               :service:service1:clean
                                  :service:service2:clean
}                                                                        :service:service1:compileJava
                                     :shared:compileJava UP-TO-DATE      :service:service1:processResources UP-TO-DATE
                                     :shared:processResources UP-TO-DATE :service:service1:classes
project(':api') {                    :shared:classes UP-TO-DATE          :service:service1:jar
  dependencies {                     :shared:jar                         :service:service1:assemble
                                     :api:compileJava
    compile project(':shared')                                           :service:service1:compileTestJava
                                     :api:processResources UP-TO-DATE    :service:service1:processTestResources UP-TO-
  }                                  :api:classes                        DATE
}                                    :api:jar                            :service:service1:testClasses
                                     :api:assemble                       :service:service1:test
                                     :api:compileTestJava
dependsOnChildren()                                                      :service:service1:check
                                     :api:processTestResources UP-TO-DATE:service:service1:build
                                     :api:testClasses                    :service:service2:compileJava
                                     :api:test                           :service:service2:processResources UP-TO-DATE
                                     :api:check                          :service:service2:classes
                                     :api:build                          :service:service2:jar
                                     :service:compileJava UP-TO-DATE     :service:service2:assemble
                                     :service:processResources UP-TO-DATE:service:service2:compileTestJava
                                     :service:classes UP-TO-DATE         :service:service2:processTestResources UP-TO-
                                     :service:jar                        DATE
                                     :service:assemble                   :service:service2:testClasses
                                     :service:compileTestJava UP-TO-DATE :service:service2:test
                                     :service:processTestResources UP-TO-DATE
                                                                         :service:service2:check
                                     :service:testClasses UP-TO-DATE     :service:service2:build
                                     :service:test UP-TO-DATE
                                     :service:check UP-TO-DATE           BUILD SUCCESSFUL
                                     :service:build
                                     :shared:assemble                    Total time: 3.75 secs
                                     :shared:compileTestJava UP-TO-DATE
                                     :shared:processTestResources UP-TO-DATE
                                     :shared:testClasses UP-TO-DATE
                                     :shared:test UP-TO-DATE
                                     :shared:check UP-TO-DATE
                                     :shared:build
PLUGINS
Extending your build
Any Gradle script can be a plug-in:
apply from: 'otherScript.gradle'
apply from: 'http://mycomp.com/otherScript.gradle'



Use many of the standard or 3rd-party plug-ins:
apply   plugin:   'java'
apply   plugin:   'groovy'
apply   plugin:   'scala'
apply   plugin:   'war'


Configuration objects can be externalized:
task configure << {
  pos = new java.text.FieldPosition(10)
  // Apply the script.
  apply from: 'position.gradle', to: pos
  println pos.beginIndex
  println pos.endIndex
                                         position.gradle:
}
                                            beginIndex = 1;
                                            endIndex = 5;
Standard plug-ins
Plug-in ID                   Plug-in ID
base                         application (java, groovy)
java-base                    jetty (war)
groovy-base                  maven (java, war)
scala-base                   osgi (java-base, java)
reporting-base               war (java)
java (java-base)             code-quality (reporting-base, java,
                             groovy)

groovy (java, groovy-base)   eclipse (java, groovy, scala, war)
scala (java, scala-base)     idea (java)
antlr (java)                 project-report (reporting-base)
announce                     sonar
READING MATERIAL
Resources
   http://www.gradle.org
    ◦ /tutorials
    ◦ /current/docs/userguide/userguide.html
    ◦ /current/docs/dsl/index.html
   http://groovy.codehaus.org
    ◦ /gapi/
    ◦ /groovy-jdk/
    ◦ /User+Guide
   http://ant.apache.org/manual
Literature
                         “Build and test software written in Java and
                         many other languages with Gradle, the open
                         source project automation tool that’s getting
                         a lot of attention. This concise introduction
                         provides numerous code examples to help
                         you explore Gradle, both as a build tool and
                         as a complete solution for automating the
                         compilation, test, and release process of
                         simple and enterprise-level applications .”




 http://shop.oreilly.com/product/0636920019909.do
QUESTIONS?

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Hibernate tutorial
Hibernate tutorialHibernate tutorial
Hibernate tutorial
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
java 8 new features
java 8 new features java 8 new features
java 8 new features
 
Jenkins tutorial
Jenkins tutorialJenkins tutorial
Jenkins tutorial
 
Java11 New Features
Java11 New FeaturesJava11 New Features
Java11 New Features
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 
Spring GraphQL
Spring GraphQLSpring GraphQL
Spring GraphQL
 
Java 8-streams-collectors-patterns
Java 8-streams-collectors-patternsJava 8-streams-collectors-patterns
Java 8-streams-collectors-patterns
 
JPA and Hibernate
JPA and HibernateJPA and Hibernate
JPA and Hibernate
 
Maven
MavenMaven
Maven
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
An Introduction to Maven
An Introduction to MavenAn Introduction to Maven
An Introduction to Maven
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
 
Java Collections
Java CollectionsJava Collections
Java Collections
 
Maven Overview
Maven OverviewMaven Overview
Maven Overview
 
Introduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformIntroduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platform
 

Destacado

Gradle: The Build System you have been waiting for!
Gradle: The Build System you have been waiting for!Gradle: The Build System you have been waiting for!
Gradle: The Build System you have been waiting for!Corneil du Plessis
 
Gradle enabled android project
Gradle enabled android projectGradle enabled android project
Gradle enabled android projectShaka Huang
 
Gradle & Android Studio - Introduction
Gradle & Android Studio - IntroductionGradle & Android Studio - Introduction
Gradle & Android Studio - IntroductionKevin Pelgrims
 
Exploring the power of Gradle in android studio - Basics & Beyond
Exploring the power of Gradle in android studio - Basics & BeyondExploring the power of Gradle in android studio - Basics & Beyond
Exploring the power of Gradle in android studio - Basics & BeyondKaushal Dhruw
 
Gradle - time for a new build
Gradle - time for a new buildGradle - time for a new build
Gradle - time for a new buildIgor Khotin
 
Gradle,the new build system for android
Gradle,the new build system for androidGradle,the new build system for android
Gradle,the new build system for androidzhang ghui
 
How to improve gradle build speed
How to improve gradle build speedHow to improve gradle build speed
How to improve gradle build speedFate Chang
 
Android sensors
Android sensorsAndroid sensors
Android sensorsdatta_jini
 
Javaone - Gradle: Harder, Better, Stronger, Faster
Javaone - Gradle: Harder, Better, Stronger, Faster Javaone - Gradle: Harder, Better, Stronger, Faster
Javaone - Gradle: Harder, Better, Stronger, Faster Andres Almiray
 
Android Fundamentals - Day 2
Android Fundamentals - Day 2Android Fundamentals - Day 2
Android Fundamentals - Day 2Mohammad Tarek
 
Android app fundamentals
Android app fundamentalsAndroid app fundamentals
Android app fundamentalsAmr Salman
 
Gradle for Android Developers
Gradle for Android DevelopersGradle for Android Developers
Gradle for Android DevelopersJosiah Renaudin
 
What’s new for Android Developers in 2015 - Material Design, Android Studio, ...
What’s new for Android Developers in 2015 - Material Design, Android Studio, ...What’s new for Android Developers in 2015 - Material Design, Android Studio, ...
What’s new for Android Developers in 2015 - Material Design, Android Studio, ...Deepu S Nath
 
Introduction to android studio 2.0 and data binding library
Introduction to android studio 2.0 and data binding libraryIntroduction to android studio 2.0 and data binding library
Introduction to android studio 2.0 and data binding libraryKaushal Dhruw
 
Android gradle-build-system-overview
Android gradle-build-system-overviewAndroid gradle-build-system-overview
Android gradle-build-system-overviewKevin He
 
From Ant to Maven to Gradle a tale of CI tools for JVM
From Ant to Maven to Gradle a tale of CI tools for JVMFrom Ant to Maven to Gradle a tale of CI tools for JVM
From Ant to Maven to Gradle a tale of CI tools for JVMBucharest Java User Group
 

Destacado (20)

Gradle
GradleGradle
Gradle
 
Gradle by Example
Gradle by ExampleGradle by Example
Gradle by Example
 
Gradle: The Build System you have been waiting for!
Gradle: The Build System you have been waiting for!Gradle: The Build System you have been waiting for!
Gradle: The Build System you have been waiting for!
 
Gradle enabled android project
Gradle enabled android projectGradle enabled android project
Gradle enabled android project
 
Gradle & Android Studio - Introduction
Gradle & Android Studio - IntroductionGradle & Android Studio - Introduction
Gradle & Android Studio - Introduction
 
Exploring the power of Gradle in android studio - Basics & Beyond
Exploring the power of Gradle in android studio - Basics & BeyondExploring the power of Gradle in android studio - Basics & Beyond
Exploring the power of Gradle in android studio - Basics & Beyond
 
Gradle - time for a new build
Gradle - time for a new buildGradle - time for a new build
Gradle - time for a new build
 
Gradle,the new build system for android
Gradle,the new build system for androidGradle,the new build system for android
Gradle,the new build system for android
 
How to improve gradle build speed
How to improve gradle build speedHow to improve gradle build speed
How to improve gradle build speed
 
Android Sensor
Android SensorAndroid Sensor
Android Sensor
 
Android sensors
Android sensorsAndroid sensors
Android sensors
 
Javaone - Gradle: Harder, Better, Stronger, Faster
Javaone - Gradle: Harder, Better, Stronger, Faster Javaone - Gradle: Harder, Better, Stronger, Faster
Javaone - Gradle: Harder, Better, Stronger, Faster
 
Android Fundamentals - Day 2
Android Fundamentals - Day 2Android Fundamentals - Day 2
Android Fundamentals - Day 2
 
Android Fundamentals
Android FundamentalsAndroid Fundamentals
Android Fundamentals
 
Android app fundamentals
Android app fundamentalsAndroid app fundamentals
Android app fundamentals
 
Gradle for Android Developers
Gradle for Android DevelopersGradle for Android Developers
Gradle for Android Developers
 
What’s new for Android Developers in 2015 - Material Design, Android Studio, ...
What’s new for Android Developers in 2015 - Material Design, Android Studio, ...What’s new for Android Developers in 2015 - Material Design, Android Studio, ...
What’s new for Android Developers in 2015 - Material Design, Android Studio, ...
 
Introduction to android studio 2.0 and data binding library
Introduction to android studio 2.0 and data binding libraryIntroduction to android studio 2.0 and data binding library
Introduction to android studio 2.0 and data binding library
 
Android gradle-build-system-overview
Android gradle-build-system-overviewAndroid gradle-build-system-overview
Android gradle-build-system-overview
 
From Ant to Maven to Gradle a tale of CI tools for JVM
From Ant to Maven to Gradle a tale of CI tools for JVMFrom Ant to Maven to Gradle a tale of CI tools for JVM
From Ant to Maven to Gradle a tale of CI tools for JVM
 

Similar a Gradle Introduction

10 Cool Facts about Gradle
10 Cool Facts about Gradle10 Cool Facts about Gradle
10 Cool Facts about GradleEvgeny Goldin
 
In the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: GradleIn the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: GradleSkills Matter
 
Gradle: The Build system you have been waiting for
Gradle: The Build system you have been waiting forGradle: The Build system you have been waiting for
Gradle: The Build system you have been waiting forCorneil du Plessis
 
Introduction to Apache Ant
Introduction to Apache AntIntroduction to Apache Ant
Introduction to Apache AntShih-Hsiang Lin
 
Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010Tomek Kaczanowski
 
Gradle - Build system evolved
Gradle - Build system evolvedGradle - Build system evolved
Gradle - Build system evolvedBhagwat Kumar
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with GradleRyan Cuprak
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with GradleRyan Cuprak
 
Idiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingIdiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingSchalk Cronjé
 
Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012alexismidon
 
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012Rajmahendra Hegde
 
Programming language for the cloud infrastructure
Programming language for the cloud infrastructureProgramming language for the cloud infrastructure
Programming language for the cloud infrastructureYaroslav Muravskyi
 
Get Grulping with JavaScript Task Runners (Matt Gifford)
Get Grulping with JavaScript Task Runners (Matt Gifford)Get Grulping with JavaScript Task Runners (Matt Gifford)
Get Grulping with JavaScript Task Runners (Matt Gifford)Future Insights
 
Making the Most of Your Gradle Build
Making the Most of Your Gradle BuildMaking the Most of Your Gradle Build
Making the Most of Your Gradle BuildAndres Almiray
 
An introduction to maven gradle and sbt
An introduction to maven gradle and sbtAn introduction to maven gradle and sbt
An introduction to maven gradle and sbtFabio Fumarola
 

Similar a Gradle Introduction (20)

10 Cool Facts about Gradle
10 Cool Facts about Gradle10 Cool Facts about Gradle
10 Cool Facts about Gradle
 
GradleFX
GradleFXGradleFX
GradleFX
 
In the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: GradleIn the Brain of Hans Dockter: Gradle
In the Brain of Hans Dockter: Gradle
 
Gradle: The Build system you have been waiting for
Gradle: The Build system you have been waiting forGradle: The Build system you have been waiting for
Gradle: The Build system you have been waiting for
 
Introduction to Apache Ant
Introduction to Apache AntIntroduction to Apache Ant
Introduction to Apache Ant
 
Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010
 
Gradle - Build system evolved
Gradle - Build system evolvedGradle - Build system evolved
Gradle - Build system evolved
 
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
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
 
Idiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin WritingIdiomatic Gradle Plugin Writing
Idiomatic Gradle Plugin Writing
 
Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012
 
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
 
DevOps Odessa #TechTalks 21.01.2020
DevOps Odessa #TechTalks 21.01.2020DevOps Odessa #TechTalks 21.01.2020
DevOps Odessa #TechTalks 21.01.2020
 
Programming language for the cloud infrastructure
Programming language for the cloud infrastructureProgramming language for the cloud infrastructure
Programming language for the cloud infrastructure
 
Get Grulping with JavaScript Task Runners (Matt Gifford)
Get Grulping with JavaScript Task Runners (Matt Gifford)Get Grulping with JavaScript Task Runners (Matt Gifford)
Get Grulping with JavaScript Task Runners (Matt Gifford)
 
Making the Most of Your Gradle Build
Making the Most of Your Gradle BuildMaking the Most of Your Gradle Build
Making the Most of Your Gradle Build
 
An introduction to maven gradle and sbt
An introduction to maven gradle and sbtAn introduction to maven gradle and sbt
An introduction to maven gradle and sbt
 
Having Fun with Play
Having Fun with PlayHaving Fun with Play
Having Fun with Play
 
Dev ops meetup
Dev ops meetupDev ops meetup
Dev ops meetup
 

Más de Dmitry Buzdin

How Payment Cards Really Work?
How Payment Cards Really Work?How Payment Cards Really Work?
How Payment Cards Really Work?Dmitry Buzdin
 
Как построить свой фреймворк для автотестов?
Как построить свой фреймворк для автотестов?Как построить свой фреймворк для автотестов?
Как построить свой фреймворк для автотестов?Dmitry Buzdin
 
How to grow your own Microservice?
How to grow your own Microservice?How to grow your own Microservice?
How to grow your own Microservice?Dmitry Buzdin
 
How to Build Your Own Test Automation Framework?
How to Build Your Own Test Automation Framework?How to Build Your Own Test Automation Framework?
How to Build Your Own Test Automation Framework?Dmitry Buzdin
 
Delivery Pipeline for Windows Machines
Delivery Pipeline for Windows MachinesDelivery Pipeline for Windows Machines
Delivery Pipeline for Windows MachinesDmitry Buzdin
 
Big Data Processing Using Hadoop Infrastructure
Big Data Processing Using Hadoop InfrastructureBig Data Processing Using Hadoop Infrastructure
Big Data Processing Using Hadoop InfrastructureDmitry Buzdin
 
Developing Useful APIs
Developing Useful APIsDeveloping Useful APIs
Developing Useful APIsDmitry Buzdin
 
Архитектура Ленты на Одноклассниках
Архитектура Ленты на ОдноклассникахАрхитектура Ленты на Одноклассниках
Архитектура Ленты на ОдноклассникахDmitry Buzdin
 
Riding Redis @ask.fm
Riding Redis @ask.fmRiding Redis @ask.fm
Riding Redis @ask.fmDmitry Buzdin
 
Rubylight JUG Contest Results Part II
Rubylight JUG Contest Results Part IIRubylight JUG Contest Results Part II
Rubylight JUG Contest Results Part IIDmitry Buzdin
 
Rubylight Pattern-Matching Solutions
Rubylight Pattern-Matching SolutionsRubylight Pattern-Matching Solutions
Rubylight Pattern-Matching SolutionsDmitry Buzdin
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
Poor Man's Functional Programming
Poor Man's Functional ProgrammingPoor Man's Functional Programming
Poor Man's Functional ProgrammingDmitry Buzdin
 
Rubylight programming contest
Rubylight programming contestRubylight programming contest
Rubylight programming contestDmitry Buzdin
 
Continuous Delivery
Continuous Delivery Continuous Delivery
Continuous Delivery Dmitry Buzdin
 
Introduction to DevOps
Introduction to DevOpsIntroduction to DevOps
Introduction to DevOpsDmitry Buzdin
 
Thread Dump Analysis
Thread Dump AnalysisThread Dump Analysis
Thread Dump AnalysisDmitry Buzdin
 

Más de Dmitry Buzdin (20)

How Payment Cards Really Work?
How Payment Cards Really Work?How Payment Cards Really Work?
How Payment Cards Really Work?
 
Как построить свой фреймворк для автотестов?
Как построить свой фреймворк для автотестов?Как построить свой фреймворк для автотестов?
Как построить свой фреймворк для автотестов?
 
How to grow your own Microservice?
How to grow your own Microservice?How to grow your own Microservice?
How to grow your own Microservice?
 
How to Build Your Own Test Automation Framework?
How to Build Your Own Test Automation Framework?How to Build Your Own Test Automation Framework?
How to Build Your Own Test Automation Framework?
 
Delivery Pipeline for Windows Machines
Delivery Pipeline for Windows MachinesDelivery Pipeline for Windows Machines
Delivery Pipeline for Windows Machines
 
Big Data Processing Using Hadoop Infrastructure
Big Data Processing Using Hadoop InfrastructureBig Data Processing Using Hadoop Infrastructure
Big Data Processing Using Hadoop Infrastructure
 
JOOQ and Flyway
JOOQ and FlywayJOOQ and Flyway
JOOQ and Flyway
 
Developing Useful APIs
Developing Useful APIsDeveloping Useful APIs
Developing Useful APIs
 
Whats New in Java 8
Whats New in Java 8Whats New in Java 8
Whats New in Java 8
 
Архитектура Ленты на Одноклассниках
Архитектура Ленты на ОдноклассникахАрхитектура Ленты на Одноклассниках
Архитектура Ленты на Одноклассниках
 
Dart Workshop
Dart WorkshopDart Workshop
Dart Workshop
 
Riding Redis @ask.fm
Riding Redis @ask.fmRiding Redis @ask.fm
Riding Redis @ask.fm
 
Rubylight JUG Contest Results Part II
Rubylight JUG Contest Results Part IIRubylight JUG Contest Results Part II
Rubylight JUG Contest Results Part II
 
Rubylight Pattern-Matching Solutions
Rubylight Pattern-Matching SolutionsRubylight Pattern-Matching Solutions
Rubylight Pattern-Matching Solutions
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Poor Man's Functional Programming
Poor Man's Functional ProgrammingPoor Man's Functional Programming
Poor Man's Functional Programming
 
Rubylight programming contest
Rubylight programming contestRubylight programming contest
Rubylight programming contest
 
Continuous Delivery
Continuous Delivery Continuous Delivery
Continuous Delivery
 
Introduction to DevOps
Introduction to DevOpsIntroduction to DevOps
Introduction to DevOps
 
Thread Dump Analysis
Thread Dump AnalysisThread Dump Analysis
Thread Dump Analysis
 

Último

UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioChristian Posta
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?IES VE
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaborationbruanjhuli
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1DianaGray10
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarPrecisely
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...DianaGray10
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8DianaGray10
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXTarek Kalaji
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7DianaGray10
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintMahmoud Rabie
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024D Cloud Solutions
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopBachir Benyammi
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAshyamraj55
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPathCommunity
 

Último (20)

UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and Istio
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity Webinar
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBX
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
201610817 - edge part1
201610817 - edge part1201610817 - edge part1
201610817 - edge part1
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership Blueprint
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 Workshop
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation Developers
 

Gradle Introduction

  • 1. Introduction to Gradle Andrey Adamovich Aestas/IT
  • 2. What is Gradle?  Gradle is a general purpose build system  It comes with a rich build description language (DSL) based on Groovy  It supports ”build-by-convention” principle  But it is very flexible and extensible  It has built-in plug-ins for Java, Groovy, Scala, Web, OSGi  It derives all the best and integrates well with Ivy, Ant and Maven
  • 3. What’s in this presentation?  Overview  Basic features & principles  Files and file collections  Dependencies  Multiple projects  Plug-ins  Reading material  Questions
  • 5. Gradle features I  Declarative builds and build-by- convention  Language for dependency based programming and many ways to manage dependencies  Groovy as a base language allows imperative programming
  • 6. Gradle features II  Deep and rich API for managing projects, tasks, dependency artefacts and much more.  State of the art support for multi- project builds  Ease of integration and migration. Ant, Maven, Ivy are supported out- of-the-box  Free and open source
  • 7. Advanced features  Parallel unit test execution  Dependency build  Incremental build support  Dynamic tasks and task rules  Gradle daemon
  • 8. Who uses Gradle?  Hibernate  Canoo  Grails  Carrier  Groovy  FCC  Spring Integration  Zeppelin  Spring Security  GPars  Griffon  Spock  Gaelyk  Aluminum  Qi4j  Gant
  • 10. Hello, Gradle! build.gradle: task hello << { println ’Hello, World' } >gradle hello :hello Hello, World! BUILD SUCCESSFUL Total time: 2.401 secs build.gradle: task hello << { print ’Hello, ' } task world(dependsOn: hello) << { println ’World!' } >gradle -q hello world Hello, World! >gradle -q world Hello, World!
  • 11. Task configuration & execution task hello message = "What's up?" hello { println "Configuring hello task." message = 'Hello, World!' } hello << { println message >gradle hello } Configuring hello task. :hello Hello, World! hello << { What's up? println project.message BUILD SUCCESSFUL } Total time: 1.958 secs
  • 12. Gradle is Groovy, Groovy is Java Java: import java.io.File; … String parentDir = new File(”test.txt”) .getAbsoluteFile() .getParentPath(); Groovy: def parentDir = new File(”test.txt”).absoluteFile.parentPath Gradle: parentDir = file(”test.txt”).absoluteFile.parentPath
  • 13. Building Java project apply plugin: 'java' >gradle clean build :clean :compileJava :processResources UP-TO-DATE :classes :jar :assemble :compileTestJava UP-TO-DATE :processTestResources UP-TO-DATE :testClasses UP-TO-DATE :test :check :build BUILD SUCCESSFUL Total time: 7.6 secs
  • 14. Java plug-in tasks compileJava processResources clean classes javadoc compileTestJava processTestResources jar testClasses test uploadArchives check assemble build
  • 15. Extending tasks test { systemProperties ("net.sourceforge.cobertura.datafile": cobSerFile) cobSerFile = "${project.buildDir}/cobertura.ser" } test.doFirst { ant { delete(file: cobSerFile, failonerror: false) 'cobertura-instrument'(datafile: cobSerFile) { fileset(dir: "${sourceSets.main.classesDir}", includes: "**/*.class") } } } } test.doLast { ant.'cobertura-report'( destdir: "${project.buildDirName}/test-results", format: 'xml', srcdir: "src/main/java", datafile: cobSerFile) }
  • 16. Ant is a first-class citizen  All Ant tasks and types can be used inside Gradle script using Groovy syntax  Whole Ant build script can be imported into Gradle and its targets can be called
  • 17. Ant usage examples I task hello << { String greeting = "hello from Ant" ant.echo(message: greeting) } task list << { def path = ant.path { fileset(dir: 'libs', includes: '*.jar') } path.list().each { println it } } task zip << { ant.zip(destfile: 'archive.zip') { fileset(dir: 'src') { include(name: '**.xml') exclude(name: '**.java') } } }
  • 18. Ant usage examples II ant.taskdef(resource: 'checkstyletask.properties') { classpath { fileset(dir: 'libs/checkstyle', includes: '*.jar') } } ant.checkstyle(config: 'src/tools/sun_checks.xml') { fileset(dir: 'src') } <project> <target name="hello"> <echo>Hello, from Ant</echo> </target> </project> >gradle hello :hello [ant:echo] Hello, from Ant ant.importBuild 'build.xml' BUILD SUCCESSFUL Total time: 7.898 secs
  • 19. Overriding conventions version = 1.0 group = ’org.gradletutorials’ version = "1.0-${new Date().format('yyyyMMdd')}" task release(dependsOn: assemble) << { println 'We release now' } build.taskGraph.whenReady { taskGraph -> if (taskGraph.hasTask(':release')) { version = '1.0’ } else { version = '1.0-SNAPSHOT’ } } sourceSets.main.java.srcDirs += ["src/generated/java"] sourceSets.main.resources.srcDirs += ["src/generated/resources"]
  • 20. More examples  Many source directory sets per project without a need of a plug-in  Different dependencies per source directory  Even different JDK per source directory  Many artifacts per project
  • 22. Referencing files & file collections Groovy-like syntax: // Using a relative path File configFile = file('src/config.xml') Create a file collection from a bunch of files: FileCollection collection = files( 'src/file1.txt', new File('src/file2.txt'), ['src/file3.txt', 'src/file4.txt']) Create a files collection by referencing project properties: collection = files { srcDir.listFiles() } Operations on collections: def union = collection + files('src/file4.txt') def different = collection - files('src/file3.txt')}
  • 23. Using file collections as input Many objects in Gradle have properties, which accept a set of input files. For example, the compile task has a source property, which defines the source files to compile. You can set the value of this property using any of the types supported by the files() method: // Use a File object to specify the source directory. compile { source = file('src/main/java') } // Using a closure to specify the source files. compile { source = { // Use the contents of each zip file in the src dir. file('src') .listFiles() .findAll { it.name.endsWith('.zip') } .collect { zipTree(it) } } } }1
  • 24. Copying files Using Ant integration: ant.copy(todir: 'javadoc') { fileset(dir: 'build/docs') } Using Gradle task type: task copyTask(type: Copy) { from 'src/main/webapp‘ into 'build/explodedWar‘ include '**/*.jsp‘ exclude { details -> details.file.name.endsWith('.html') && details.file.text.contains('staging') } }
  • 26. Repository configuration repositories { mavenCentral() } repositories { mavenCentral name: 'single-jar-repo', urls: "http://repo.mycompany.com/jars" mavenCentral name: 'multi-jar-repos', urls: ["http://repo.mycompany.com/jars1", "http://repo.mycompany.com/jars1"] } repositories { flatDir name: 'localRepository', dirs: 'lib' flatDir dirs: ['lib1', 'lib2'] } repositories { add(new org.apache.ivy.plugins.resolver.FileSystemResolver()) { name = 'localRepository' latestStrategy = new org.apache.ivy.plugins.latest.LatestTimeStrategy() addArtifactPattern(libDir + '/[organization]/[artifact]/[ext]s/[artifact]-[revision].[ext]') } }
  • 27. Referencing dependencies dependencies { runtime files('libs/a.jar', 'libs/b.jar') runtime fileTree(dir: 'libs', includes: ['*.jar']) } dependencies { compile 'org.springframework:spring-webmvc:3.0.0.RELEASE' testCompile 'org.springframework:spring-test:3.0.0.RELEASE' testCompile 'junit:junit:4.7' } dependencies { runtime group: 'org.springframework', name: 'spring-core', version: '2.5' runtime 'org.springframework:spring-core:2.5', 'org.springframework:spring-aop:2.5 } List groovy = ["org.codehaus.groovy:groovy-all:1.5.4@jar", "commons-cli:commons-cli:1.0@jar", "org.apache.ant:ant:1.7.0@jar"] List hibernate = ['org.hibernate:hibernate:3.0.5@jar', 'somegroup:someorg:1.0@jar'] dependencies { runtime groovy, hibernate }
  • 28. Transitive dependencies configurations.compile.transitive = true dependencies { compile 'org.springframework:spring-webmvc:3.0.0.RC2' runtime 'org.hibernate:hibernate:3.0.5' } dependencies { compile 'org.springframework:spring-webmvc:3.0.0.RC2' runtime('org.hibernate:hibernate:3.0.5') { transitive = true } }
  • 30. Directories & settings.gradle settings.gradle: include 'shared', 'api', ':service:service1', ':service:service2'  You can have only one build file for the whole multi-project build  All properties, settings, plug-ins, dependencies are derived without a need to duplicate information  You can override almost all behaviour in child builds
  • 31. All or something allprojects { task build << { println "Building project: " + project.name } } >gradle build :build subprojects { Building project: 90-multi-project task prebuild << { :api:prebuild println "It is subproject!" It is subproject! :api:build } Building project: api build.dependsOn prebuild :service:prebuild } It is subproject! :service:build Building project: service :shared:prebuild It is subproject! :shared:build Building project: shared :service:service1:prebuild It is subproject! :service:service1:build Building project: service1 :service:service2:prebuild It is subproject! :service:service2:build Building project: service2 BUILD SUCCESSFUL Total time: 9.684 secs
  • 32. Inter-project dependencies subprojects { apply plugin: 'java' if (project.name.matches('^.*serviced+$')) { dependencies { >gradle clean build compile project(':api') :api:clean compile project(':shared') :service:clean } :shared:clean } :service:service1:clean :service:service2:clean } :service:service1:compileJava :shared:compileJava UP-TO-DATE :service:service1:processResources UP-TO-DATE :shared:processResources UP-TO-DATE :service:service1:classes project(':api') { :shared:classes UP-TO-DATE :service:service1:jar dependencies { :shared:jar :service:service1:assemble :api:compileJava compile project(':shared') :service:service1:compileTestJava :api:processResources UP-TO-DATE :service:service1:processTestResources UP-TO- } :api:classes DATE } :api:jar :service:service1:testClasses :api:assemble :service:service1:test :api:compileTestJava dependsOnChildren() :service:service1:check :api:processTestResources UP-TO-DATE:service:service1:build :api:testClasses :service:service2:compileJava :api:test :service:service2:processResources UP-TO-DATE :api:check :service:service2:classes :api:build :service:service2:jar :service:compileJava UP-TO-DATE :service:service2:assemble :service:processResources UP-TO-DATE:service:service2:compileTestJava :service:classes UP-TO-DATE :service:service2:processTestResources UP-TO- :service:jar DATE :service:assemble :service:service2:testClasses :service:compileTestJava UP-TO-DATE :service:service2:test :service:processTestResources UP-TO-DATE :service:service2:check :service:testClasses UP-TO-DATE :service:service2:build :service:test UP-TO-DATE :service:check UP-TO-DATE BUILD SUCCESSFUL :service:build :shared:assemble Total time: 3.75 secs :shared:compileTestJava UP-TO-DATE :shared:processTestResources UP-TO-DATE :shared:testClasses UP-TO-DATE :shared:test UP-TO-DATE :shared:check UP-TO-DATE :shared:build
  • 34. Extending your build Any Gradle script can be a plug-in: apply from: 'otherScript.gradle' apply from: 'http://mycomp.com/otherScript.gradle' Use many of the standard or 3rd-party plug-ins: apply plugin: 'java' apply plugin: 'groovy' apply plugin: 'scala' apply plugin: 'war' Configuration objects can be externalized: task configure << { pos = new java.text.FieldPosition(10) // Apply the script. apply from: 'position.gradle', to: pos println pos.beginIndex println pos.endIndex position.gradle: } beginIndex = 1; endIndex = 5;
  • 35. Standard plug-ins Plug-in ID Plug-in ID base application (java, groovy) java-base jetty (war) groovy-base maven (java, war) scala-base osgi (java-base, java) reporting-base war (java) java (java-base) code-quality (reporting-base, java, groovy) groovy (java, groovy-base) eclipse (java, groovy, scala, war) scala (java, scala-base) idea (java) antlr (java) project-report (reporting-base) announce sonar
  • 37. Resources  http://www.gradle.org ◦ /tutorials ◦ /current/docs/userguide/userguide.html ◦ /current/docs/dsl/index.html  http://groovy.codehaus.org ◦ /gapi/ ◦ /groovy-jdk/ ◦ /User+Guide  http://ant.apache.org/manual
  • 38. Literature “Build and test software written in Java and many other languages with Gradle, the open source project automation tool that’s getting a lot of attention. This concise introduction provides numerous code examples to help you explore Gradle, both as a build tool and as a complete solution for automating the compilation, test, and release process of simple and enterprise-level applications .” http://shop.oreilly.com/product/0636920019909.do