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:
- notify-send
- Snarl
- Growl
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. | |
Snarl, for Windows | |
terminal-notifier, OS X | |
notification center OS X (since Mavericks) | |
notify-send for Linux | |
SystemTray since Java 6 | |
Pushbullet | |
Kdialog for KDE | |
notifu for Windows | |
AnyBar for OS X and Linux | |
Toaster for Windows 8 | |
Notify since Java 6 | |
BurntToast for Windows 10 | |
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!