第二十二章. 标准的 Gradle 插件

Chapter 22. Standard Gradle plugins

Gradle 的发行包中有大量的插件。如下列所示:
There are a number of plugins included in the Gradle distribution. These are listed below.

22.1. 语言插件

22.1. Language plugins

这些插件添加了让各种语言可以被编译和在JVM执行的支持。
These plugins add support for various languages which can be compiled for and executed in the JVM.

表 22.1. 语言插件
Table 22.1. Language plugins

插件 Id
Plugin Id
自动应用
Automatically applies
与什么插件一起使用
Works with
描述
Description
java java-base -

向一个项目添加 Java 编译、 测试和捆绑的能力。它是很多其他 Gradle 插件的基础服务。另请参阅 第 7 章, Java 快速入门
Adds Java compilation, testing and bundling capabilities to a project. It serves as the basis for many of the other Gradle plugins. See also Chapter 7, Java Quickstart .

groovy java , groovy-base -

添加对 Groovy 项目构建的支持。另请参阅 第9章, Groovy 快速入门
Adds support for building Groovy projects. See also Chapter 9, Groovy Quickstart .

scala java , scala-base -

添加对 Scala 项目构建的支持。
Adds support for building Scala projects.

antlr java -

添加对使用 Antlr作为生成解析器的支持。
Adds support for generating parsers using Antlr .

22.2. 正在孵化的语言插件

22.2. Incubating language plugins

这些插件添加了对多种语言的支持:
These plugins add support for various languages:

表 22.2. 语言插件
Table 22.2. Language plugins

插件 Id
Plugin Id
自动应用
Automatically applies
与什么插件一起使用
Works with
描述
Description
assembler - -

向项目添加本机汇编语言的功能。
Adds native assembly language capabilities to a project.

c - -

向项目添加 C语言源代码编译功能。
Adds C source compilation capabilities to a project.

cpp - -

向项目添加 c++ 源代码编译功能。
Adds C++ source compilation capabilities to a project.

objective-c - -

向项目中添加 Objective-C 源代码编译功能。
Adds Objective-C source compilation capabilities to a project.

objective-cpp - -

向项目中添加 Objective-C++ 源代码编译功能。
Adds Objective-C++ source compilation capabilities to a project.

windows-resources - -

添加对在本地bin文件中包含 Windows 资源的支持。
Adds support for including Windows resources in native binaries.

22.3. 集成插件

22.3. Integration plugins

以下这些插件提供了一些与各种运行时技术的集成。
These plugins provide some integration with various runtime technologies.

表 22.3. 集成插件
Table 22.3. Integration plugins

插件 Id
Plugin Id
自动应用
Automatically applies
与什么插件一起使用
Works with
描述
Description
application java -

添加了一些任务,用于运行和捆绑一个Java项目作为命令行应用程序。
Adds tasks for running and bundling a Java project as a command-line application.

ear - java

添加用于构建 J2EE 应用程序的支持。
Adds support for building J2EE applications.

jetty war -

在构建中部署你的web程序到一个内嵌的Jetty web容器中。另请参阅 第 10 章, Web 应用程序快速入门
Deploys your web application to a Jetty web container embedded in the build. See also Chapter 10, Web Application Quickstart .

maven - java , war

添加用于将项目发布到 Maven 仓库的支持。
Adds support for publishing artifacts to Maven repositories.

osgi java-base java

添加构建 OSGi 捆绑包的支持。
Adds support for building OSGi bundles.

war java -

添加用于组装 web 应用程序的 WAR 文件的支持。另请参阅 第 10 章, Web 应用程序快速入门。 Adds support for assembling web application WAR files. See also Chapter 10, Web Application Quickstart .

22.4. 孵化中的集成插件

22.4. Incubating integration plugins

以下这些插件提供了一些与各种运行时技术的集成。
These plugins provide some integration with various runtime technologies.

表 22.4. 孵化中的集成插件
Table 22.4. Incubating integration plugins

插件 Id
Plugin Id
自动应用
Automatically applies
与什么插件一起使用
Works with
描述
Description
distribution - -

添加构建 ZIP 和 TAR 分发包的支持。
Adds support for building ZIP and TAR distributions.

java-library-distribution java , distribution -

添加构建一个Java类库的 ZIP 和 TAR 分发包的支持。
Adds support for building ZIP and TAR distributions for a Java library.

ivy-publish - java , war

这个插件提供了新的 DSL,用于支持发布文件到 Ivy 存储库,改善了现有的 DSL。
This plugin provides a new DSL to support publishing artifacts to Ivy repositories, which improves on the existing DSL.

maven-publish - java , war

这个插件提供了新的 DSL,用于支持发布文件到 Maven 存储库,改善了现有的 DSL。
This plugin provides a new DSL to support publishing artifacts to Maven repositories, which improves on the existing DSL.

22.5. 软件开发插件

22.5. Software development plugins

这些插件提供一些软件开发过程上的帮助。
These plugins provide help with your software development process.

表 22.5. 软件开发插件
Table 22.5. Software development plugins

插件 Id
Plugin Id
自动应用
Automatically applies
与什么插件一起使用
Works with
描述
Description
announce - -

将消息发布到你所喜爱的平台,如 Twitter 或 Growl。
Publish messages to your favourite platforms, such as Twitter or Growl.

build-announcements announce -

在构建的生命周期中,把本地公告中有关你感兴趣的事件发送到你的桌面。
Sends local announcements to your desktop about interesting events in the build lifecycle.

checkstyle java-base -

使用 Checkstyle对您的项目的 Java 源文件执行质量检查并生成报告。
Performs quality checks on your project's Java source files using Checkstyle and generates reports from these checks.

codenarc groovy-base -

使用 CodeNarc对您的项目的 Groovy 源文件执行质量检查并生成报告。
Performs quality checks on your project's Groovy source files using CodeNarc and generates reports from these checks.

eclipse - java , groovy , scala

生成 Eclipse IDE所用到的文件,从而使项目能够导入到 Eclipse。另请参阅 第 7 章, Java 快速入门
Generates files that are used by Eclipse IDE , thus making it possible to import the project into Eclipse. See also Chapter 7, Java Quickstart .

eclipse-wtp - ear , war

与 eclipse 插件一样,但它还生成 eclipse WTP (Web 工具平台) 的配置文件。你的war/ear项目在导入eclipse 后,应配置为能在 WTP 中使用。另请参阅 第 7 章, Java 快速入门
Does the same as the eclipse plugin plus generates eclipse WTP (Web Tools Platform) configuration files. After importing to eclipse your war/ear projects should be configured to work with WTP. See also Chapter 7, Java Quickstart .

findbugs java-base -

使用 FindBugs对您的项目的 Java 源文件执行质量检查并生成报告。
Performs quality checks on your project's Java source files using FindBugs and generates reports from these checks.

idea - java

生成 Intellij IDEA IDE所用到的文件,从而使项目能够导入到 IDEA。
Generates files that are used by Intellij IDEA IDE , thus making it possible to import the project into IDEA.

jdepend java-base -

使用 JDepend对您的项目的源文件执行质量检查并生成报告。
Performs quality checks on your project's source files using JDepend and generates reports from these checks.

pmd java-base -

使用 PMD对您的项目的 Java 源文件执行质量检查并生成报告。
Performs quality checks on your project's Java source files using PMD and generates reports from these checks.

project-report reporting-base -

生成关于Gradle构建中有用的信息的报告。
Generates reports containing useful information about your Gradle build.

signing base -

添加对生成的文件或构件进行数字签名的功能。
Adds the ability to digitally sign built files and artifacts.

sonar - java-base, java, jacoco

提供对 Sonar代码质量平台的集成。由 sonar-runner 插件取代。
Provides integration with the Sonar code quality platform. Superceeded by the sonar-runner plugin.

22.6. 孵化中的软件开发插件

22.6. Incubating software development plugins

这些插件提供一些软件开发过程上的帮助。
These plugins provide help with your software development process.

表 22.6. 软件开发插件
Table 22.6. Software development plugins

插件 Id
Plugin Id
自动应用
Automatically applies
与什么插件一起使用
Works with
描述
Description
build-dashboard reporting-base -

生成构建的主控面板的报表。
Generates build dashboard report.

build-init wrapper -

添加用于初始化一个新 Gradle 构建的支持。处理转换 Maven 构建为 Gradle 构建。
Adds support for initializing a new Gradle build. Handles converting a Maven build to a Gradle build.

cunit - -

添加用于运行 CUnit测试的支持。
Adds support for running CUnit tests.

jacoco reporting-base java

提供对 Java 的 JaCoCo代码覆盖率库的集成。
Provides integration with the JaCoCo code coverage library for Java.

sonar-runner - java-base, java, jacoco

提供对 Sonar代码质量平台的集成。由 sonar 插件取代。
Provides integration with the Sonar code quality platform. Supersedes the sonar plugin.

visual-studio - 本机语言插件
native language plugins

添加对 Visual Studio 的集成。
Adds integration with Visual Studio.

wrapper - -

添加一个用于生成 Gradle wrapper 文件的 Wrapper 任务。
Adds a Wrapper task for generating Gradle wrapper files.

22.7. 基本插件

22.7. Base plugins

这些插件组成了基本的构建块,其他插件都由此组装而来。它们可供你在你的构建文件中使用,并在此处完整列出。然而,请注意它们都不被认为是 Gradle 公共 API 的一部分。因此,这些插件都不在用户指南中记录。您可能会引用他们的 API 文档,以了解更多关于它们的信息。
These plugins form the basic building blocks which the other plugins are assembled from. They are available for you to use in your build files, and are listed here for completeness. However, be aware that they are not yet considered part of Gradle's public API. As such, these plugins are not documented in the user guide. You might refer to their API documentation to learn more about them.

表 22.7. 基本插件
Table 22.7. Base plugins

插件 Id
Plugin Id
描述
Description
base

添加标准的生命周期任务,并为归档任务默认进行合理的配置:
Adds the standard lifecycle tasks and configures reasonable defaults for the archive tasks:

  • 添加构建 ConfigurationName 任务。这些任务组装成属于指定配置的构件。
    adds build ConfigurationName tasks. Those tasks assemble the artifacts belonging to the specified configuration.
  • 添加上传 ConfigurationName 任务。这些任务组装并上传属于指定的配置的构件。
    adds upload ConfigurationName tasks. Those tasks assemble and upload the artifacts belonging to the specified configuration.
  • 为所有归档任务配置合适的默认值(比如从 AbstractArchiveTask 继承来任务)。例如,以下类型的归档任务: Jar Tar Zip 。特别是,归档任务的 destinationDirbaseNameversion属性被预先配置了默认值。这是非常有用的,因为它促进了跨项目的一致性 ;完成了有关构件命名规范及构建之后的位置上的一致。
    configures reasonable default values for all archive tasks (e.g. tasks that inherit from AbstractArchiveTask ). For example, the archive tasks are tasks of types: Jar , Tar , Zip . Specifically, destinationDir , baseName and version properties of the archive tasks are preconfigured with defaults. This is extremely useful because it drives consistency across projects; the consistency regarding naming conventions of archives and their location after the build completed.

java-base

对项目添加源集的概念。不会添加任何特定的源集。 Adds the source sets concept to the project. Does not add any particular source sets.

groovy-base

向项目中添加Groovy 的源集概念。
Adds the Groovy source sets concept to the project.

scala-base

向项目中添加Scala 的源集概念。
Adds the Scala source sets concept to the project.

reporting-base

将一些共享的公约属性添加到项目中,它们与报告的生成有关。
Adds some shared convention properties to the project, relating to report generation.

22.8. 第三方插件

22.8. Third party plugins

你可以在 维基上找到外部插件的列表。
You can find a list of external plugins on the wiki .