第三十章. CodeNarc 插件

Chapter 30. The CodeNarc Plugin

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

30.1. 用法

30.1. Usage

要使用 CodeNarc 插件,请在构建脚本中包含以下语句:
To use the CodeNarc plugin, include in your build script:

示例 30.1. 使用 CodeNarc 插件
Example 30.1. Using the CodeNarc plugin

build.gradle

apply plugin: 'codenarc'

该插件向你的项目添加了大量的执行质量检查的任务。你可以通过运行 gradle check 执行检查。
The plugin adds a number of tasks to the project that perform the quality checks. You can execute the checks by running gradle check .

30.2. 任务

30.2. Tasks

CodeNarc 插件向project 中添加了以下任务:
The CodeNarc plugin adds the following tasks to the project:

表 30.1. CodeNarc 插件 - 任务
Table 30.1. CodeNarc plugin - tasks

任务名称
Task name
依赖于
Depends on
类型
Type
描述
Description
codenarcMain - CodeNarc 针对生产 Groovy 源文件运行 CodeNarc。
Runs CodeNarc against the production Groovy source files.
codenarcTest - CodeNarc 针对测试 Groovy 源文件运行 CodeNarc。
Runs CodeNarc against the test Groovy source files.
codenarcSourceSet - CodeNarc 针对给定的source set 的 Groovy 源文件运行 CodeNarc。
Runs CodeNarc against the given source set's Groovy source files.

CodeNarc 插件向 Groovy 插件所加入的任务添加了以下的依赖。
The CodeNarc plugin adds the following dependencies to tasks defined by the Groovy plugin.

表 30.2. CodeNarc 插件 - 附加的任务依赖
Table 30.2. CodeNarc plugin - additional task dependencies

任务名称
Task name
依赖于
Depends on
check 所有的 CodeNarc 任务,包括 codenarcMaincodenarcTest
All CodeNarc tasks, including codenarcMain and codenarcTest .

30.3. 项目布局

30.3. Project layout

CodeNarc 插件预计是以下的项目布局:
The CodeNarc plugin expects the following project layout:

表 30.3. CodeNarc 插件 - 项目布局
Table 30.3. CodeNarc plugin - project layout

文件
File
意义
Meaning
config/codenarc/codenarc.xml CodeNarc 配置文件
CodeNarc configuration file

30.4. 依赖管理

30.4. Dependency management

CodeNarc 插件添加了下列的依赖配置:
The CodeNarc plugin adds the following dependency configurations:

表30.4. CodeNarc 插件 ​​- 依赖配置
Table 30.4. CodeNarc plugin - dependency configurations

名称
Name
意义
Meaning
codenarc 使用的 CodeNarc 库
The CodeNarc libraries to use

30.5. 配置

30.5. Configuration

请参阅 CodeNarcExtension
See CodeNarcExtension .