第四十一章. 项目报告插件

Chapter 41. The Project Report Plugin

项目报告插件向项目添加了一些任务,用于生成包含有关构建的有用信息的报告。这些任务生成的内容,与由gradle tasksgradle dependenciesgradle properties 触发的命令行报告完全相同(见第11.6节,《获取有关构建的信息》)。与命令行报告相比,报告插件会将报告生成到文件中。这里还有一个聚合任务,它依赖于该插件添加的所有报告任务。
The Project report plugin adds some tasks to your project which generate reports containing useful information about your build. Those tasks generate exactly the same content as the command line reports triggered by gradle tasks, gradle dependencies and gradle properties (see Section 11.6, “Obtaining information about your build”). In contrast to the command line reports, the report plugin generates the reports into a file. There is also an aggregating task that depends on all report tasks added by the plugin.

我们计划在未来发布的版本中,向现有的报告添加更多的内容,并创建其他报告。
We plan to add much more to the existing reports and create additional ones in future releases of Gradle.

41.1. 用法

41.1. Usage

要使用项目报告插件,请在构建脚本中包含:
To use the Project report plugin, include in your build script:

apply plugin: 'project-report'

41.2. 任务

41.2. Tasks

项目报告插件定义了以下任务:
The project report plugin defines the following tasks:

表 41.1. 项目报告插件——任务 - Table 41.1. Project report plugin - tasks

任务名称
Task name
依赖于
Depends on
类型
Type
描述
Description
dependencyReport - DependencyReportTask 生成项目依赖项报告。
Generates the project dependency report.
htmlDependencyReport - HtmlDependencyReportTask 为项目或项目集生成 HTML 依赖和依赖洞察报告。
Generates an HTML dependency and dependency insight report for the project or a set of projects.
propertyReport - PropertyReportTask 生成项目属性报告。
Generates the project property report.
taskReport - TaskReportTask 生成项目任务报告。
Generates the project task report.
projectReport dependencyReport, propertyReport, taskReport, htmlDependencyReport Task 生成所有项目报告。
Generates all project reports.

41.3. 项目布局

41.3. Project layout

项目报告插件不需要任何特定的项目布局。
The project report plugin does not require any particular project layout.

41.4. 依赖管理

41.4. Dependency management

项目报告插件没有定义任何的依赖配置。
The project report plugin does not define any dependency configurations.

41.5. 约定属性

41.5. Convention properties

项目报告定义了以下约定属性:
The project report defines the following convention properties:

表 41.2. 项目报告插件——约定属性 - Table 41.2. Project report plugin - convention properties

属性名称
Property name
类型
Type
默认值
Default value
描述
Description
reportsDirName String reports 相对于构建目录,生成报告的目录的名称。
The name of the directory to generate reports into, relative to the build directory.
reportsDir File (只读)
File (read-only)
buildDir/reportsDirName 要生成报告的目录。
The directory to generate reports into.
projects Set<Project> 一个单元素的集合,元素为应用了该插件的项目。
A one element set with the project the plugin was applied to.
要生成报告的所有项目。
The projects to generate the reports for.
projectReportDirName String project 生成项目报告的目录名称,它是相对于报告目录的相对路径。
The name of the directory to generate the project report into, relative to the reports directory.
projectReportDir File (只读)
File (read-only)
reportsDir/projectReportDirName 生成项目报告的目录。
The directory to generate the project report into.

这些约定属性由一个ProjectReportsPluginConvention 类型的约定对象提供。
These convention properties are provided by a convention object of type ProjectReportsPluginConvention.