Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rock the Gradle, Rule the World

Rock the Gradle, Rule the World

Xavier Gouchet

April 01, 2019
Tweet

More Decks by Xavier Gouchet

Other Decks in Programming

Transcript

  1. Rock the Gradle
    Rule the world

    View Slide

  2. About…
    Lead Android Engineer
    at WorkWell
    Fluent in Android since Cupcake
    2

    View Slide

  3. A brief introduction
    1

    View Slide

  4. Dependency
    Management
    System
    What is Gradle
    General
    Purpose
    Build
    management
    4

    View Slide

  5. 5
    General purpose
    Language agnostic
    Feature agnostic

    View Slide

  6. 6
    Dependency
    management
    system
    Knows how to graph and resolve dependencies
    ◇ code
    ◇ tasks
    ◇ …

    View Slide

  7. 7
    Build management
    Based on tasks created by plugins

    View Slide

  8. Configuration
    Gradle flow
    Initialisation Execution
    8

    View Slide

  9. 9
    Initialisation
    Launches the JVM (with proper params)
    Analyse the working directory
    Reads the settings.gradle file
    Creates the Project object(s) that will be used
    Compiles, test and add buildSrc to the classpath

    View Slide

  10. 10
    Configuration
    Execute all the build.gradle scripts in the project
    Create all the Task objects and configure the Project
    object(s)
    Resolves the tasks dependencies

    View Slide

  11. 11
    Execution
    List the Task to run based on the invocation (and their
    dependencies)
    Execute each of the tasks

    View Slide

  12. Meet the buildSrc
    folder
    2

    View Slide

  13. Project structure
    ┬ MyProject
    ├┬ app/
    │├── src/
    │└── build.gradle
    ├┬ buildSrc/
    │├── src/
    │├── build.gradle
    │└── settings.gradle
    ├─ build.gradle
    └─ settings.gradle
    13

    View Slide

  14. Purposes…
    ◇ Better dependency management
    ◇ Helper classes / methods
    ◇ Custom tasks in dedicated classes
    ◇ Custom plugin
    ■ Locally versionned with the project
    14

    View Slide

  15. How does it work?
    ◇ Works like any module in your project
    ◇ Compiled and tested before any gradle task
    ◇ Groovy, Java, Kotlin, …
    ◇ Any public class / method becomes availble in
    gradle scripts
    15

    View Slide

  16. “ A change in buildSrc causes the whole
    project to become out-of-date.
    16

    View Slide

  17. apply plugin: 'groovy'
    dependencies {
    compile gradleApi()
    compile localGroovy()
    }
    17
    Default build.gradle

    View Slide

  18. Writin a Plugin
    3

    View Slide

  19. Hands On
    19

    View Slide

  20. Thanks!
    Any questions?
    ◇ https://github.com/xgouchet/RockTheGradle
    ◇ @xgouchet
    20

    View Slide