Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction...
Transcript of Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction...
![Page 1: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/1.jpg)
Building Software with Gradle -!An Introduction
Etienne Studer!Tooling Lead, [email protected]
Donat Csikos!Principal Engineer, [email protected]
![Page 2: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/2.jpg)
Gradle
Thousands of dependent modulesMulti-dimensional build variantsHighly tested frameworks
The Enterprise Build System
![Page 3: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/3.jpg)
PollUsing Gradle?
![Page 4: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/4.jpg)
• Build is difficult to read, maintain, and extend
• Weak support to model project dependencies
• Build system dictates project layout
• Slow build performance
• Incompatible build system versions
• Build system restricts project automation
Build Pain Points
![Page 5: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/5.jpg)
• Deeply model the domain
• Provide declarative domain-specific language
Core Concepts
![Page 6: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/6.jpg)
Core Gradle Objects• Task
• Project
• Plugin
• Dependency
• Component
![Page 7: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/7.jpg)
Tasks• Unit of work
• Declarativ
• Typed
! task testClassesJar(type: Jar) {! from ‘build/classes/test’! classifier = 'test'! manifest.attributes provider: 'Gradle'! }!!!
![Page 8: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/8.jpg)
Task Dependencies• Directed
• Acyclic
! assemble.dependsOn testClassesJar!! assemble.dependsOn ‘sourcesJar’!!
task sourcesJar(type: Jar) {! from sourceSets.main.java! classifier = ‘sources'! }!
![Page 9: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/9.jpg)
• Each task to be executed is a node
• The dependsOn relations define directed edges
• Each task executed once and only once
• Execution order is against the edge directions
Task Graph (DAG)
![Page 10: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/10.jpg)
Plugins• Provide tasks
• Provide task types
• Configure tasks of other plugins
• Register build listeners
! apply plugin: ‘java’! apply plugin: ‘application’
![Page 11: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/11.jpg)
• Can be applied from any local/remote M2 repository ! buildscript {! repositories {! jcenter()! }! dependencies {! classpath ‘nu.studer:gradle-jooq-plugin:1.0.5'! }! }!! apply plugin: ‘nu.studer.jooq'
External Plugins
![Page 12: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/12.jpg)
Projects• Have plugins applied
• Contain child projects
• Contain tasks
• Contain configurations
![Page 13: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/13.jpg)
Project Dependencies• Project dependencies and external dep. declared in configurations
• Configurations provided by plugin or defined in script ! repositories { maven { url ‘https://my.repo.org’! credentials {! username ‘user‘! password ‘password‘! } } }!! dependencies {! compile project(‘api’)! testCompile ‘junit:junit:4.8.1‘! }
http://www.gradle.org/docs/current/userguide/dependency_management.html
![Page 14: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/14.jpg)
Demo!
!
!
!
![Page 15: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/15.jpg)
Gradle Object Model• Object graph can be traversed ! allprojects {! repositories {! jcenter()! }! }!! allprojects {! def zipTasks = tasks.withType(Zip)! def imgZipTasks = zipTasks.matching { it.name.startsWith('images') }! imgZipTasks.all {! classifier = 'IMAGES'! }! }!! task imagesJar(type: Jar) {! from 'images'! }
![Page 16: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/16.jpg)
Implicit Task Dependencies• Model the input of tasks as the output of other tasks
so Gradle can build the correct task graph ! task docsZip(type: Zip) {! into('java') {! from project(‘:SUB1').javadoc! }! into('scala') {! from scaladoc! }! }!
![Page 17: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/17.jpg)
Task uptodate checks!
!
Only run task if its input or output has changed since the previous run
!
Define inputs and outputs on your custom tasks!
Inputs —> Task —> Outputs
http://www.gradle.org/docs/current/userguide/more_about_tasks.html
![Page 18: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/18.jpg)
Demo!
!
!
!
![Page 19: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/19.jpg)
Multi-Project Build• Gradle project structure defined in settings.gradle
• Arbitrary mapping from physical to logical structure
• Partial builds supported • Gradle tasks buildDependents and buildNeeded
http://www.gradle.org/docs/current/userguide/build_lifecycle.html
![Page 20: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/20.jpg)
Dependency Management• Most powerful dependency management today • Many options for version conflict resolution !repositories {! jcenter()! mavenCenter()! mavenLocal()! maven { url ‘http://myrepo.org' }! flatDir { dirs ‘lib' }!}!!configurations.compile ‘com.google.guava:guava:17.0’!
![Page 21: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/21.jpg)
DSLCustom Domain-Specific Language
!! android {! compileSdkVersion 21! buildToolsVersion ’21.0.2’! defaultConfig {! applicationId ‘ch.example.android.foo’! minSdkVersion 15! targetSdkVersion 21! }! buildTypes {! release {! runProguard false! proguardFiles getDefaultProguardFile(‘proguard-android.txt')! }! }! }
Android-Specific Language
![Page 22: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/22.jpg)
Hidden build complexity
![Page 24: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/24.jpg)
Custom plugins• Reusable build logic
• Plain Java / Groovy project
• Package in .jar file with plugin descriptor
• Upload to repository (JCenter, MavenC, private)
!
plugindev plugin simplifies bundling & publishing https://github.com/etiennestuder/gradle-plugindev-plugin
http://plugins.gradle.org/submit
![Page 25: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/25.jpg)
Policies• Enforce company policies through init scripts !
http://www.gradle.org/docs/current/userguide/init_scripts.html
gradle.taskGraph.whenReady {! allprojects { Project project ->! def androidExtension = project.extensions.findByName('android')! if (androidExtension) {! def release = androidExtension.buildTypes.find { def buildType ->! buildType.name == 'release'! }! if(release && !release.runProguard){! def msg = "Build type '$release.name' must run proGuard."! throw new IllegalStateException(msg)! }! }! }!}
![Page 26: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/26.jpg)
Gradle Wrapper• No setup on CI/Dev machines required
• Different versions of Gradle for different projects
• Gradle version persisted in version control system
http://www.gradle.org/docs/current/userguide/gradle_wrapper.html
![Page 27: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/27.jpg)
Gradle Daemon• Reuse JVM with same settings between builds
• ~/.gradle/gradle.properties org.gradle.daemon=true
• GRADLE_OPTS -Dorg.gradle.daemon=true!
• Command Line ! ! gradlew tasks --daemon (--no-daemon)
http://www.gradle.org/docs/current/userguide/gradle_daemon.html
GradleLauncher
Cmd Line
GradleDaemon
GradleDaemon
![Page 28: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/28.jpg)
Tooling API• Proxy for embedding Gradle
• Extension mechanism to provide custom models
• Forward and backward compatible
http://www.gradle.org/docs/current/userguide/embedding.html
Client VM with gradle-tooling-api.jar
Gradle Daemon for Gradle build
get build models
invoke build tasks
![Page 29: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/29.jpg)
Unified Build• Gradle as the single source of build logic
Gradle Cmd LineIDE Tooling API
CI Server
![Page 30: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/30.jpg)
Demo!
!
!
!
![Page 31: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/31.jpg)
Coming soon• Parallel task execution
• Configuration phase enhancements
• New JVM language plugins
![Page 32: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/32.jpg)
Summary
Gradle is an extensible build language that targets
usability, maintainability, extensibility, and performance for complex builds.
![Page 33: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/33.jpg)
Resources• Gradle Userguide
http://www.gradle.org/docs/current/userguide/userguide_single.html
!
• Gradle Reference Guide http://www.gradle.org/docs/current/dsl/
!
• Gradle Forum http://forums.gradle.org/gradle
![Page 34: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/34.jpg)
Conferences• EclipseCon 2015
https://www.eclipsecon.org/na2015
!
• Gradle Summit June 2015 http://www.gradlesummit.com
![Page 35: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/35.jpg)
Gradleware• Gradle development
• Open-Source
• Gradle training • Virtual training, On-site training
• Services and consulting • Gradle, Automation, Continuous Integration & Delivery
https://www.gradleware.com/
![Page 36: Building Software with Gradle - An Introduction · Building Software with Gradle -! An Introduction Etienne Studer! Tooling Lead, Gradleware ! etienne.studer@gradleware.com Donat](https://reader030.fdocuments.us/reader030/viewer/2022040402/5e832e4f56e0e65db146f091/html5/thumbnails/36.jpg)
Building Software with Gradle -!An Introduction
Etienne Studer!Tooling Lead, [email protected]
Donat Csikos!Principal Engineer, [email protected]