SlideShare une entreprise Scribd logo
1  sur  26
Gradle (http://www.gradle.org)
Maxim Stepanenko, Architect


           www.ExigenServices.com
Traditional build systems


•   Make, autotools
•   Ant (build, deploy), ant + ivy (dependency mgmt.)
•   Maven (dependency and lifecycle mgmt.)
•   Can be extended using plugins



Plug-in architectures severely limit the ability for build tools to grow gracefully as projects
become more complex. We have come to feel that plug-ins are
the wrong level of abstraction, and prefer language-based tools
like Gradle and Rake instead, because they offer finer-grained
abstractions and more flexibility long term.

http://thoughtworks.fileburst.com/assets/technology-radar-october-2012.pdf




2
Alternative build systems


•   Gradle (DSL + groovy + Ivy)
•   Rake (DSL + ruby)
•   Apache Buildr (DSL + ruby)
•   Scons (DSL + python)
•   Simple Build Tool (Scala + DSL)
•   All this systems based on a true languages: ruby, python etc.




3
Brief Gradle benefits


•   You could script parts of the build that were too difficult to describe through "build by convention".
•   The general flexibility to define the build and directories the way that seemed to make sense.
•   The entire conceptualization of the build process is much cleaner. You not only have dependencies between
    modules but you can also define dependencies on tasks, modules, directories. It is already possible to say that one
    module depends on the compiled classes of another module as opposed to the output (jar) of the module.
•   Each project/module can have multiple "source sets". A "source set" defines a named group of source directories,
    output directories, resource directories.
•   "how am I going to solve this?" as opposed to "what are the viable options my build tool is going to leave me to
    achieve this?"
•   "incremental build“. It understands when things have changed and when they have not and when certain portions
    of the build are really needed.
•   Can publish artifacts to Maven repositories and generate accurate POM.
•   IDE project generation (Eclipse – spring tool suite + greclipse / IntelliJ).



https://community.jboss.org/wiki/GradleWhy?_sscc=t




4
Gradle usage in real world


•   Hibernate
•   Grails
•   Groovy
•   SpringIntegration
•   SpringSecurity




5
Gradle build file 1
apply plugin: 'java'
apply plugin: 'eclipse‘

sourceCompatibility = '1.7'
targetCompatibility = '1.7'

version = '1.0'

jar {
  manifest {
      attributes 'Implementation-Title': ‘Title’, 'Implementation-Version': version
  }
}
repositories {
  mavenCentral()
}

dependencies {
  compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.2'
  testCompile group: 'junit', name: 'junit', version: '4.10'
}
…
}


     6
Gradle build file 2


task simpleCalculation << {
     def x = 30
     def y = 20
     if( x > y) {
            print 'x > y: ' + x + " - " + y + " = " + (x - y)
     }
     else {
            print ' x < y: ' + y + " - " + x + " = " + (y - x)
     }
}
task simple (dependsOn: ‘simpleCalculation’, description: ‘Simple task’){
            doFirst {
                        print "doFirst: ${it.name}" + System.getProperty("line.separator")
            }
}



   7
Build options


•   gradle jar
•   gradle --daemon jar
•   GRADLE_OPTS="-Dorg.gradle.daemon=true"
•   gradle --gui
•   gradle --profile
•   gradle --dry-run  run tasks without execution




8
Plugins


•   apply plugin: 'java'
•   apply plugin: 'eclipse‘
•   apply plugin: 'scala‘
•   apply plugin: 'application'
•   apply plugin: 'maven'
•   apply plugin: 'signing'




9
Source sets (SS)


• Java plugin source sets (main, test)
• Provided tasks: compile<SS>Java, process<SS>Resources, <SS>Classes
• Add new source set




10
1.
api/java
api/resources

2.
sourceSets {
   api
   main {
     compileClasspath = compileClasspath + files(api.output.classesDir)
   }
}
classes.dependsOn apiClasses

3.
gradle build




   11
Dependency management

• Groovy use Ivy under the hood + some syntactic sugar
• Support maven and Ivy repositories + custom repositories
• Logical groups of dependencies (compile group, testCompile group)
• Transitive version conflicts (different sl4j-api versions)
configurations.all {
  resolutionStrategy {
    failOnVersionConflict()
  }
}
gradle dependencies




12
Testing


• JUnit tests by defaul
• TestNG as well, test.useTestNG()
• Configurable
test {
         systemProperty 'sysProp', 'value'
         jvmArgs '-Xms256m', '-Xmx512m'
         debug = true
         ignoreFailures = true
         enableAssertions = true
         maxParallelForks = 4
         forkEvery = 10 // create new thread after 10 tests
}




13
Running, publishing


•    Run application (apply plugin: ‘application’ )
•    Startup scripts (for win and linux)
•    Zip archive (with lib folder)
•    Publish jar and zip files to repositories (gradle uploadArchives)
•    Publish to maven repository
•    Publish signed artifacts (PGP only)




14
Publish to local maven repository

apply plugin: 'maven'

archivesBaseName = "algorithms"
group = 'com.max.algorithms'
version = '1.0'


uploadArchives {
  repositories {
    mavenDeployer {
       repository(url: 'file:./maven')
     }
  }
}




    15
Multi-project builds


•    DAG full dependency traversation
•    Hierarchical structure
•    Flat structure
•    Possible to have one build file per multi module project
•    Define dependencies between tasks in different projects
•    Compile/runtime dependencies between projects




16
Mixed languages projects


• C++, scala, groovy
• Cross compiled source bases
• Fast scala compilation (similar to SBT)

     apply plugin: 'scala‘
     ext.scala_version = '2.9.2'
     sourceSets.main.scala.srcDir "src/main/java"
     sourceSets.main.java.srcDirs = []

     dependencies {
       scalaTools group: 'org.scala-lang', name: 'scala-compiler', version: scala_version
       scalaTools group: 'org.scala-lang', name: 'scala-library', version: scala_version

         compile group: 'org.scalatra', name: 'scalatra_2.9.1', version: '2.1.0.M1'
         runtime group: 'org.scalatra', name: 'scalatra_2.9.1', version: '2.1.0.M1'
     }
17
18
Code quality


•    gradle check
•    Checkstyle
•    PMD
•    FindBugs
•    JDepend
•    Sonar
•    CodeNarc (static analyzer for groovy code)




19
Checkstyle results




20
Findbugs




21
JDepend




22
PMD




23
Custom tasks


task info(type: InfoTask)

class InfoTask extends DefaultTask {
         @TaskAction
         def info(){
                  print “Current Gradle version:
         $project.gradle.gradleVersion”
         }
}




24
Custom plugin

apply plugin: InfoPlugin

class InfoPlugin implements Plugin<Project> {
   void apply(Project project) {
     project.task('info') << {
        println "Running Gradle: $project.gradle.gradleVersion"
     }
   }
}




  25
Continuous integration


• Jenkins (gradle plugin)
• JetBrains TeamCity
• Atlassian Bamboo




26

Contenu connexe

Tendances

The world of gradle - an introduction for developers
The world of gradle  - an introduction for developersThe world of gradle  - an introduction for developers
The world of gradle - an introduction for developersTricode (part of Dept)
 
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...ZeroTurnaround
 
Gradle 3.0: Unleash the Daemon!
Gradle 3.0: Unleash the Daemon!Gradle 3.0: Unleash the Daemon!
Gradle 3.0: Unleash the Daemon!Eric Wendelin
 
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
 
Managing dependencies with gradle
Managing dependencies with gradleManaging dependencies with gradle
Managing dependencies with gradleLiviu Tudor
 
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
 
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
 
Gradle - time for another build
Gradle - time for another buildGradle - time for another build
Gradle - time for another buildIgor Khotin
 
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
 
Basic Gradle Plugin Writing
Basic Gradle Plugin WritingBasic Gradle Plugin Writing
Basic Gradle Plugin WritingSchalk Cronjé
 
うさぎ組 in G* WorkShop -うさみみの日常-
うさぎ組 in G* WorkShop -うさみみの日常-うさぎ組 in G* WorkShop -うさみみの日常-
うさぎ組 in G* WorkShop -うさみみの日常-kyon mm
 
NetBeans Support for EcmaScript 6
NetBeans Support for EcmaScript 6NetBeans Support for EcmaScript 6
NetBeans Support for EcmaScript 6Kostas Saidis
 
Gradle plugins, take it to the next level
Gradle plugins, take it to the next levelGradle plugins, take it to the next level
Gradle plugins, take it to the next levelEyal Lezmy
 
Gradle enabled android project
Gradle enabled android projectGradle enabled android project
Gradle enabled android projectShaka Huang
 

Tendances (19)

The world of gradle - an introduction for developers
The world of gradle  - an introduction for developersThe world of gradle  - an introduction for developers
The world of gradle - an introduction for developers
 
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
[Image Results] Java Build Tools: Part 2 - A Decision Maker's Guide Compariso...
 
Gradle 3.0: Unleash the Daemon!
Gradle 3.0: Unleash the Daemon!Gradle 3.0: Unleash the Daemon!
Gradle 3.0: Unleash the Daemon!
 
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!
 
Building with Gradle
Building with GradleBuilding with Gradle
Building with Gradle
 
Gradle
GradleGradle
Gradle
 
Managing dependencies with gradle
Managing dependencies with gradleManaging dependencies with gradle
Managing dependencies with gradle
 
Introduction to gradle
Introduction to gradleIntroduction to gradle
Introduction to gradle
 
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
 
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
 
Gradle in 45min
Gradle in 45minGradle in 45min
Gradle in 45min
 
Gradle - time for another build
Gradle - time for another buildGradle - time for another build
Gradle - time for another build
 
Hands on the Gradle
Hands on the GradleHands on the Gradle
Hands on the Gradle
 
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
 
Basic Gradle Plugin Writing
Basic Gradle Plugin WritingBasic Gradle Plugin Writing
Basic Gradle Plugin Writing
 
うさぎ組 in G* WorkShop -うさみみの日常-
うさぎ組 in G* WorkShop -うさみみの日常-うさぎ組 in G* WorkShop -うさみみの日常-
うさぎ組 in G* WorkShop -うさみみの日常-
 
NetBeans Support for EcmaScript 6
NetBeans Support for EcmaScript 6NetBeans Support for EcmaScript 6
NetBeans Support for EcmaScript 6
 
Gradle plugins, take it to the next level
Gradle plugins, take it to the next levelGradle plugins, take it to the next level
Gradle plugins, take it to the next level
 
Gradle enabled android project
Gradle enabled android projectGradle enabled android project
Gradle enabled android project
 

En vedette (18)

Javaone - Gradle: Harder, Better, Stronger, Faster
Javaone - Gradle: Harder, Better, Stronger, Faster Javaone - Gradle: Harder, Better, Stronger, Faster
Javaone - Gradle: Harder, Better, Stronger, Faster
 
Gradle
GradleGradle
Gradle
 
Android Gradle about using flavor
Android Gradle about using flavorAndroid Gradle about using flavor
Android Gradle about using flavor
 
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
 
JSON Web Tokens (JWT)
JSON Web Tokens (JWT)JSON Web Tokens (JWT)
JSON Web Tokens (JWT)
 
Why gradle
Why gradle Why gradle
Why gradle
 
Profsoux2014 presentation by Pavelchuk
Profsoux2014 presentation by PavelchukProfsoux2014 presentation by Pavelchuk
Profsoux2014 presentation by Pavelchuk
 
Agile Project Grows
Agile Project GrowsAgile Project Grows
Agile Project Grows
 
Quality Principles
Quality PrinciplesQuality Principles
Quality Principles
 
Apache Maven presentation from BitByte conference
Apache Maven presentation from BitByte conferenceApache Maven presentation from BitByte conference
Apache Maven presentation from BitByte conference
 
How to develop your creativity
How to develop your creativityHow to develop your creativity
How to develop your creativity
 
Time Management
Time ManagementTime Management
Time Management
 
Non Blocking Algorithms at Traffic Conditions
Non Blocking Algorithms at Traffic ConditionsNon Blocking Algorithms at Traffic Conditions
Non Blocking Algorithms at Traffic Conditions
 
Apache Maven 2 Part 2
Apache Maven 2 Part 2Apache Maven 2 Part 2
Apache Maven 2 Part 2
 
Windows Azure: Quick start
Windows Azure: Quick startWindows Azure: Quick start
Windows Azure: Quick start
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Successful interview for a young IT specialist
Successful interview for a young IT specialistSuccessful interview for a young IT specialist
Successful interview for a young IT specialist
 
English for E-mails
English for E-mailsEnglish for E-mails
English for E-mails
 

Similaire à Gradle Build System Overview

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
 
10 Cool Facts about Gradle
10 Cool Facts about Gradle10 Cool Facts about Gradle
10 Cool Facts about GradleEvgeny Goldin
 
Gradle - Build system evolved
Gradle - Build system evolvedGradle - Build system evolved
Gradle - Build system evolvedBhagwat Kumar
 
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
 
Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Ryan Cuprak
 
Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01Tino Isnich
 
Android gradle-build-system-overview
Android gradle-build-system-overviewAndroid gradle-build-system-overview
Android gradle-build-system-overviewKevin He
 
Everything as a Code / Александр Тарасов (Одноклассники)
Everything as a Code / Александр Тарасов (Одноклассники)Everything as a Code / Александр Тарасов (Одноклассники)
Everything as a Code / Александр Тарасов (Одноклассники)Ontico
 
Make Your Build Great Again (DroidConSF 2017)
Make Your Build Great Again (DroidConSF 2017)Make Your Build Great Again (DroidConSF 2017)
Make Your Build Great Again (DroidConSF 2017)Jared Burrows
 
Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010Tomek Kaczanowski
 
Everything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPLEverything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPLMario-Leander Reimer
 
Everything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventureEverything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventureQAware GmbH
 
Commit to excellence - Java in containers
Commit to excellence - Java in containersCommit to excellence - Java in containers
Commit to excellence - Java in containersRed Hat Developers
 
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
 

Similaire à Gradle Build System Overview (20)

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
 
10 Cool Facts about Gradle
10 Cool Facts about Gradle10 Cool Facts about Gradle
10 Cool Facts about Gradle
 
Gradle - Build system evolved
Gradle - Build system evolvedGradle - Build system evolved
Gradle - Build system evolved
 
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
 
Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]
 
Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01
 
Android gradle-build-system-overview
Android gradle-build-system-overviewAndroid gradle-build-system-overview
Android gradle-build-system-overview
 
Everything as a Code / Александр Тарасов (Одноклассники)
Everything as a Code / Александр Тарасов (Одноклассники)Everything as a Code / Александр Тарасов (Одноклассники)
Everything as a Code / Александр Тарасов (Одноклассники)
 
Everything as a code
Everything as a codeEverything as a code
Everything as a code
 
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
 
React inter3
React inter3React inter3
React inter3
 
Make Your Build Great Again (DroidConSF 2017)
Make Your Build Great Again (DroidConSF 2017)Make Your Build Great Again (DroidConSF 2017)
Make Your Build Great Again (DroidConSF 2017)
 
Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010Gradle talk, Javarsovia 2010
Gradle talk, Javarsovia 2010
 
Everything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPLEverything-as-code. A polyglot adventure. #DevoxxPL
Everything-as-code. A polyglot adventure. #DevoxxPL
 
Everything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventureEverything-as-code - A polyglot adventure
Everything-as-code - A polyglot adventure
 
Commit to excellence - Java in containers
Commit to excellence - Java in containersCommit to excellence - Java in containers
Commit to excellence - Java in containers
 
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
 

Plus de Return on Intelligence

Types of testing and their classification
Types of testing and their classificationTypes of testing and their classification
Types of testing and their classificationReturn on Intelligence
 
Service design principles and patterns
Service design principles and patternsService design principles and patterns
Service design principles and patternsReturn on Intelligence
 
Differences between Testing in Waterfall and Agile
Differences between Testing in Waterfall and AgileDifferences between Testing in Waterfall and Agile
Differences between Testing in Waterfall and AgileReturn on Intelligence
 
Организация внутренней системы обучения
Организация внутренней системы обученияОрганизация внутренней системы обучения
Организация внутренней системы обученияReturn on Intelligence
 
Shared position in a project: testing and analysis
Shared position in a project: testing and analysisShared position in a project: testing and analysis
Shared position in a project: testing and analysisReturn on Intelligence
 
Оценка задач выполняемых по итеративной разработке
Оценка задач выполняемых по итеративной разработкеОценка задач выполняемых по итеративной разработке
Оценка задач выполняемых по итеративной разработкеReturn on Intelligence
 
Velocity как инструмент планирования и управления проектом
Velocity как инструмент планирования и управления проектомVelocity как инструмент планирования и управления проектом
Velocity как инструмент планирования и управления проектомReturn on Intelligence
 

Plus de Return on Intelligence (19)

Types of testing and their classification
Types of testing and their classificationTypes of testing and their classification
Types of testing and their classification
 
Service design principles and patterns
Service design principles and patternsService design principles and patterns
Service design principles and patterns
 
Differences between Testing in Waterfall and Agile
Differences between Testing in Waterfall and AgileDifferences between Testing in Waterfall and Agile
Differences between Testing in Waterfall and Agile
 
Windows azurequickstart
Windows azurequickstartWindows azurequickstart
Windows azurequickstart
 
Организация внутренней системы обучения
Организация внутренней системы обученияОрганизация внутренней системы обучения
Организация внутренней системы обучения
 
Shared position in a project: testing and analysis
Shared position in a project: testing and analysisShared position in a project: testing and analysis
Shared position in a project: testing and analysis
 
Introduction to Business Etiquette
Introduction to Business EtiquetteIntroduction to Business Etiquette
Introduction to Business Etiquette
 
Agile Testing Process
Agile Testing ProcessAgile Testing Process
Agile Testing Process
 
Оценка задач выполняемых по итеративной разработке
Оценка задач выполняемых по итеративной разработкеОценка задач выполняемых по итеративной разработке
Оценка задач выполняемых по итеративной разработке
 
Meetings arranging
Meetings arrangingMeetings arranging
Meetings arranging
 
The art of project estimation
The art of project estimationThe art of project estimation
The art of project estimation
 
Risk Management
Risk ManagementRisk Management
Risk Management
 
Resolving conflicts
Resolving conflictsResolving conflicts
Resolving conflicts
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Principles of personal effectiveness
Principles of personal effectivenessPrinciples of personal effectiveness
Principles of personal effectiveness
 
Cross-cultural communication
Cross-cultural communicationCross-cultural communication
Cross-cultural communication
 
Velocity как инструмент планирования и управления проектом
Velocity как инструмент планирования и управления проектомVelocity как инструмент планирования и управления проектом
Velocity как инструмент планирования и управления проектом
 
Testing your code
Testing your codeTesting your code
Testing your code
 
Reports Project
Reports ProjectReports Project
Reports Project
 

Gradle Build System Overview

  • 1. Gradle (http://www.gradle.org) Maxim Stepanenko, Architect www.ExigenServices.com
  • 2. Traditional build systems • Make, autotools • Ant (build, deploy), ant + ivy (dependency mgmt.) • Maven (dependency and lifecycle mgmt.) • Can be extended using plugins Plug-in architectures severely limit the ability for build tools to grow gracefully as projects become more complex. We have come to feel that plug-ins are the wrong level of abstraction, and prefer language-based tools like Gradle and Rake instead, because they offer finer-grained abstractions and more flexibility long term. http://thoughtworks.fileburst.com/assets/technology-radar-october-2012.pdf 2
  • 3. Alternative build systems • Gradle (DSL + groovy + Ivy) • Rake (DSL + ruby) • Apache Buildr (DSL + ruby) • Scons (DSL + python) • Simple Build Tool (Scala + DSL) • All this systems based on a true languages: ruby, python etc. 3
  • 4. Brief Gradle benefits • You could script parts of the build that were too difficult to describe through "build by convention". • The general flexibility to define the build and directories the way that seemed to make sense. • The entire conceptualization of the build process is much cleaner. You not only have dependencies between modules but you can also define dependencies on tasks, modules, directories. It is already possible to say that one module depends on the compiled classes of another module as opposed to the output (jar) of the module. • Each project/module can have multiple "source sets". A "source set" defines a named group of source directories, output directories, resource directories. • "how am I going to solve this?" as opposed to "what are the viable options my build tool is going to leave me to achieve this?" • "incremental build“. It understands when things have changed and when they have not and when certain portions of the build are really needed. • Can publish artifacts to Maven repositories and generate accurate POM. • IDE project generation (Eclipse – spring tool suite + greclipse / IntelliJ). https://community.jboss.org/wiki/GradleWhy?_sscc=t 4
  • 5. Gradle usage in real world • Hibernate • Grails • Groovy • SpringIntegration • SpringSecurity 5
  • 6. Gradle build file 1 apply plugin: 'java' apply plugin: 'eclipse‘ sourceCompatibility = '1.7' targetCompatibility = '1.7' version = '1.0' jar { manifest { attributes 'Implementation-Title': ‘Title’, 'Implementation-Version': version } } repositories { mavenCentral() } dependencies { compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.2' testCompile group: 'junit', name: 'junit', version: '4.10' } … } 6
  • 7. Gradle build file 2 task simpleCalculation << { def x = 30 def y = 20 if( x > y) { print 'x > y: ' + x + " - " + y + " = " + (x - y) } else { print ' x < y: ' + y + " - " + x + " = " + (y - x) } } task simple (dependsOn: ‘simpleCalculation’, description: ‘Simple task’){ doFirst { print "doFirst: ${it.name}" + System.getProperty("line.separator") } } 7
  • 8. Build options • gradle jar • gradle --daemon jar • GRADLE_OPTS="-Dorg.gradle.daemon=true" • gradle --gui • gradle --profile • gradle --dry-run  run tasks without execution 8
  • 9. Plugins • apply plugin: 'java' • apply plugin: 'eclipse‘ • apply plugin: 'scala‘ • apply plugin: 'application' • apply plugin: 'maven' • apply plugin: 'signing' 9
  • 10. Source sets (SS) • Java plugin source sets (main, test) • Provided tasks: compile<SS>Java, process<SS>Resources, <SS>Classes • Add new source set 10
  • 11. 1. api/java api/resources 2. sourceSets { api main { compileClasspath = compileClasspath + files(api.output.classesDir) } } classes.dependsOn apiClasses 3. gradle build 11
  • 12. Dependency management • Groovy use Ivy under the hood + some syntactic sugar • Support maven and Ivy repositories + custom repositories • Logical groups of dependencies (compile group, testCompile group) • Transitive version conflicts (different sl4j-api versions) configurations.all { resolutionStrategy { failOnVersionConflict() } } gradle dependencies 12
  • 13. Testing • JUnit tests by defaul • TestNG as well, test.useTestNG() • Configurable test { systemProperty 'sysProp', 'value' jvmArgs '-Xms256m', '-Xmx512m' debug = true ignoreFailures = true enableAssertions = true maxParallelForks = 4 forkEvery = 10 // create new thread after 10 tests } 13
  • 14. Running, publishing • Run application (apply plugin: ‘application’ ) • Startup scripts (for win and linux) • Zip archive (with lib folder) • Publish jar and zip files to repositories (gradle uploadArchives) • Publish to maven repository • Publish signed artifacts (PGP only) 14
  • 15. Publish to local maven repository apply plugin: 'maven' archivesBaseName = "algorithms" group = 'com.max.algorithms' version = '1.0' uploadArchives { repositories { mavenDeployer { repository(url: 'file:./maven') } } } 15
  • 16. Multi-project builds • DAG full dependency traversation • Hierarchical structure • Flat structure • Possible to have one build file per multi module project • Define dependencies between tasks in different projects • Compile/runtime dependencies between projects 16
  • 17. Mixed languages projects • C++, scala, groovy • Cross compiled source bases • Fast scala compilation (similar to SBT) apply plugin: 'scala‘ ext.scala_version = '2.9.2' sourceSets.main.scala.srcDir "src/main/java" sourceSets.main.java.srcDirs = [] dependencies { scalaTools group: 'org.scala-lang', name: 'scala-compiler', version: scala_version scalaTools group: 'org.scala-lang', name: 'scala-library', version: scala_version compile group: 'org.scalatra', name: 'scalatra_2.9.1', version: '2.1.0.M1' runtime group: 'org.scalatra', name: 'scalatra_2.9.1', version: '2.1.0.M1' } 17
  • 18. 18
  • 19. Code quality • gradle check • Checkstyle • PMD • FindBugs • JDepend • Sonar • CodeNarc (static analyzer for groovy code) 19
  • 24. Custom tasks task info(type: InfoTask) class InfoTask extends DefaultTask { @TaskAction def info(){ print “Current Gradle version: $project.gradle.gradleVersion” } } 24
  • 25. Custom plugin apply plugin: InfoPlugin class InfoPlugin implements Plugin<Project> { void apply(Project project) { project.task('info') << { println "Running Gradle: $project.gradle.gradleVersion" } } } 25
  • 26. Continuous integration • Jenkins (gradle plugin) • JetBrains TeamCity • Atlassian Bamboo 26