Chapter 60. The CodeNarc Plugin

Table of Contents

60.1. Usage
60.2. Tasks
60.3. Project layout
60.4. Dependency management
60.5. Configuration

The CodeNarc plugin performs quality checks on your project’s Groovy source files using CodeNarc and generates reports from these checks.

60.1. Usage

To use the CodeNarc plugin, include the following in your build script:

Example 60.1. Using the CodeNarc plugin


apply plugin: 'codenarc'

The plugin adds a number of tasks to the project that perform the quality checks when used with the Groovy Plugin. You can execute the checks by running gradle check.

60.2. Tasks

The CodeNarc plugin adds the following tasks to the project:

Table 60.1. CodeNarc plugin - tasks

Task name Depends on Type Description




Runs CodeNarc against the production Groovy source files.




Runs CodeNarc against the test Groovy source files.




Runs CodeNarc against the given source set’s Groovy source files.

The CodeNarc plugin adds the following dependencies to tasks defined by the Groovy plugin.

Table 60.2. CodeNarc plugin - additional task dependencies

Task name Depends on


All CodeNarc tasks, including codenarcMain and codenarcTest.

60.3. Project layout

The CodeNarc plugin expects the following project layout:

Table 60.3. CodeNarc plugin - project layout

File Meaning


CodeNarc configuration file

60.4. Dependency management

The CodeNarc plugin adds the following dependency configurations:

Table 60.4. CodeNarc plugin - dependency configurations

Name Meaning


The CodeNarc libraries to use

60.5. Configuration

See the CodeNarcExtension class in the API documentation.