Jake Ouellette (@jakeout) is a Software Engineer at Twitter who is working on the Crashlytics mobile crash reporting tool. Jake’s primary responsibilities include developing build-tool and IDE plugins which integrate the Crashlytics mobile SDK into applications. In this brief video, he shares five lessons to electrify Gradle plugins.
Crashlytics takes a bug report and then presents a web interface that points out the exact line of code where a crash occurred. This is no easy task as most developers obfuscate code deployed to mobile devices and Crashlytics has some special features that allow developers to get an exact line number for an error even if the application is obfuscated. To accomplish this the build needs to incorporate a mapping file.
To accomplish this, Ouellette had to build a Gradle plugin. Ouellette gives an overview of Gradle Plugins [2:30], shows you how to add a plugin to a Gradle build [3:00], and explains what happens to a Gradle build when you apply a plugin [3:40]. Crashlytics was about to create a Gradle plugin in a handful of days with the direct assistance of Hans Dockter.
Lesson 1: Keep the Android Gradle Plugin Up-to-date
Since the announcement on May 15th, the Gradle Android plugin has have several releases comprised of hundreds of bug fixes and several new features. For example, the Crashlytics plugin will cause an OutOfMemory exception in 0.4, but in 0.5.4 this problem has been addressed. If you are using Gradle plugins or development Gradle plugins that sit atop the Gradle Android plugin you should certainly keep the Gradle Android plugin up to date.
Lesson 2: Use Task Event Listeners
Add an event listener and then every time an event is added you can inspect the event and add new capabilities to the event. This is what allows Crashlytics to inspect and customize tasks that are automatically added by the Gradle Android plugin. (This is a key fact of this presentation, Jake’s plugin builds atop the Gradle Android plugin. So he needs a way to list tasks created for build flavors and variants.)
Lesson 3: Other Gradle Plugins Provide Helpful APIs
Crashlytics wanted to be able to react to different flavors and behave differently. The initial versions of the Crashlytics Gradle plugin was just using string and pointing directly to directories, but this was error prone. Instead of keeping track of directories, the Crashlytics Gradle plugin can use the rich API that is available in the Gradle Android plugin and in core Gradle plugins to locate files. Pay attention to the API provide both by Gradle and by other plugins.
Lesson 4: You Can Provide Properties Too!
Just as you have acess to a rich API in Core Gradle tasks and other Gradle plugins, your own plugins can offer new properties and APIs.
Lesson 5: Gradle Makes this Easy
For our users Gradle makes thing very easy. In Gradle you only have to add five lines of code to use the Crashlytics plugin. In Maven, you need 32 lines of code.
Image may be NSFW.
Clik here to view.
The post Five Lessons to Electrify Gradle Plugins from Twitter University appeared first on Gradle.