Desktop notifications for Gradle

This post is also available in: fr

When building projects, time can pass slowly… Most of the time they run as background tasks and I like to have a notification when they have finished.
There is a built-in plugin for Gradle to send notifications but we’ll see how to get more possible notifiers !

Gradle Build Announcements

This is the built-in plugin distributed with Gradle. It relies on Announce plugin, which allow sending custom notifications during a build.
It comes with four possible implementations:

  • twitter
  • notify-send
  • Snarl
  • Growl

growl.success growl.failure

It is easy to activate, just add in your build.gradle:

apply plugin: 'build-announcements'

or use it in $HOME/.gradle/init.gradle to have the plugin running by default for all your Gradle projects:

rootProject {
    apply plugin: 'build-announcements'
}

It is really nice to have this functionality available without extra installation… But there is not so much tools available and sent notifications lack of visual distinction (icon is always the same whatever the build result).

Gradle notifier

As I already have written my own notifications for Maven with maven-notifier, I have just migrated them to run with Gradle in gradle-notifier!

It comes with support for:

Notifier Screenshot
Growl, for Windows and OS X. Growl
Snarl, for Windows Snarl
terminal-notifier, OS X terminal-notifier
notification center OS X (since Mavericks) notification-center
notify-send for Linux notify-send
SystemTray since Java 6 System Tray
Pushbullet pushbullet
Kdialog for KDE Kdialog
notifu for Windows notifu
AnyBar for OS X and Linux anybar
Toaster for Windows 8 Toaster
Notify since Java 6 Notify
BurntToast for Windows 10 BurntToast
Slack Slack

Installation

Plugin can be configured in an initialization script or directly in a build script.

Initialization script

Create (or edit) file $HOME/.gradle/init.gradle:

initscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath group: 'fr.jcgay', name: 'gradle-notifier', version: '1.1.0'
    }
}

rootProject {
    apply plugin: fr.jcgay.gradle.notifier.GradleNotifierPlugin
}

Build script

In your build.gradle, add:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath group: 'fr.jcgay', name: 'gradle-notifier', version: '1.1.0'
    }
}

apply plugin: 'fr.jcgay.gradle-notifier'

or by using the plugin mechanism introduced in Gradle 2.1:

plugins {
  id "fr.jcgay.gradle-notifier" version "1.1.0"
}

Configuration

It relies on send-notification, notifiers configuration and which notifier to use can be set in $HOME/.send-notification (See available parameters in current documentation).

Or the plugin can be configured using Gradle extension in targeted script:

notifier {
    implementation = 'notificationcenter'
    threshold {
        time = 10
        unit = java.util.concurrent.TimeUnit.SECONDS
    }
    growl {
        port = 23053
        host = 'localhost'
        password = 'azerty123'
    }

Here it is! No more excuses to forgot your ran a build somewhere!

comments powered by Disqus