Droidcon Create Your Gradle Plugin

19
Create your Gradle plugin Nabil Hachicha Droidcon - 2014

description

Code sample: https://github.com/nhachicha/sample_gradle_plugin Video: http://youtu.be/xoSkz0ICWG4 Gradle is becoming more & more adopted by developers as their main build system especially after the release of Android Studio. Thanks to the plugins architecture, Gradle allows users to reuse patterns and practices, avoiding boilerplate build code. In this session, we will focus on creating a Plugin that cooperate with the existing "android plugin", in order to demonstrate some key concepts like: Tasks, Lifecycle, defining a custom DSL, incremental build and testing ... we conclude by giving an overview of some useful Plugins that will boost your CI process.

Transcript of Droidcon Create Your Gradle Plugin

Page 1: Droidcon Create Your Gradle Plugin

Create your Gradle plugin

Nabil Hachicha

Droidcon - 2014

Page 2: Droidcon Create Your Gradle Plugin

About Me

Works at The App Business London

Open Source contributorsnappydb.com

@nhachicha@nabil_hachicha

Page 3: Droidcon Create Your Gradle Plugin

Motivation

What is a Gradle Plugin?

Page 4: Droidcon Create Your Gradle Plugin

Motivation

• A reusable fragment of build logic

• Define the How (Tasks) & the What (DSL)

Page 5: Droidcon Create Your Gradle Plugin

Motivation

What are the benefits?

Page 6: Droidcon Create Your Gradle Plugin

Motivation

• Keeping the build simple & concise

• Reduce boilerplate build code (no copy/paste)

• Separation of concern How (Tasks) vs the What (configuration)

Page 7: Droidcon Create Your Gradle Plugin

Use case study

A plugin that generates a properties file

Page 8: Droidcon Create Your Gradle Plugin

Gradle Tasks

Demo

Page 9: Droidcon Create Your Gradle Plugin

Writing a lifecycle hook

Page 10: Droidcon Create Your Gradle Plugin

Writing a lifecycle hook

dependsOndisplayRevision

Page 11: Droidcon Create Your Gradle Plugin

Writing a lifecycle hook

Demo

Page 12: Droidcon Create Your Gradle Plugin
Page 13: Droidcon Create Your Gradle Plugin

Extra properties

• User-defined variables

• Ex: use it to disable or enable the plugin for a specific flavour

Page 14: Droidcon Create Your Gradle Plugin

Custom Task

• Structure your code into classes & methods

• Maintainability (any method is fully testable)

• Reusability

Page 15: Droidcon Create Your Gradle Plugin

DSL

• Task add new functionality (ability To Do Things - they

are unit of works)

• Extension add new build language elements To Talk about Things

Page 16: Droidcon Create Your Gradle Plugin

Incremental Build

• Input haven't changed & Output is still there = Skip redundant work. but…

• You need to tell gradle what's the Input & Output

Page 17: Droidcon Create Your Gradle Plugin
Page 18: Droidcon Create Your Gradle Plugin

Thanks!

Q/A

Page 19: Droidcon Create Your Gradle Plugin

@nhachicha@nabil_hachicha

The App Business is hiring!theappbusiness.com/careers/ Source Code & Slides