第四十二章. 公告插件

Chapter 42. The Announce Plugin

Gradle 公告允许在构建期间发送自定义通知,它支持以下通知系统:
The Gradle announce allows to send custom announcements during a build. The following notification systems are supported:

42.1. 用法

42.1. Usage

要使用公告插件,请在构建脚本中应用它:
To use the announce plugin, apply it to your build script:

示例 42.1. 使用公告插件 - Example 42.1. Using the announce plugin

build.gradle

apply plugin: 'announce'

接下来,配置你所选择的通知服务(请参阅下表,了解可用的配置属性):
Next, configure your notification service(s) of choice (see table below for which configuration properties are available):

示例 42.2. 配置公告插件 - Example 42.2. Configure the announce plugin

build.gradle

announce {
  username = 'myId'
  password = 'myPassword'
}

最后,使用announce方法发送公告:
Finally, send announcements with the announce method:

示例 42.3. 使用公告插件 - Example 42.3. Using the announce plugin

build.gradle

task helloWorld << {
    println "Hello, world!"
}  

helloWorld.doLast {
    announce.announce("helloWorld completed!", "twitter")
    announce.announce("helloWorld completed!", "local")
}

announce 方法有两个 String 参数: 要被发送的消息,以及要使用的通知服务。下表列出了支持的通知服务以及它们的配置属性。
The announce method takes two String arguments: The message to be sent, and the notification service to be used. The following table lists supported notification services and their configuration properties.

表 42.1. 公告插件通知服务 - Table 42.1. Announce Plugin Notification Services

通知服务
Notification Service
操作系统
Operating System
配置属性
Configuration Properties
补充信息
Further Information
twitter 任意
Any
username, password
snarl Windows
growl Mac OS X
notify-send Ubuntu 需要安装notify-send软件包。可以使用sudo apt-get install libnotify-bin来安装它。
Requires the notify-send package to be installed. Use sudo apt-get install libnotify-bin to install it.
local Windows, Mac OS X, Ubuntu 根据当前的操作系统在 snarl,growl和notify-send之间自动选择。
Automatically chooses between snarl, growl, and notify-send depending on the current operating system.

42.2. 配置

42.2. Configuration

请参阅 AnnouncePluginExtension
See AnnouncePluginExtension.