The CodeNarc Plugin
The CodeNarc plugin performs quality checks on your project’s Groovy source files using CodeNarc and generates reports from these checks.
Usage
To use the CodeNarc plugin, include the following in your build script:
plugins {
codenarc
}
plugins {
id '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.
Tasks
The CodeNarc plugin adds the following tasks to the project:
Dependencies added to other tasks
The CodeNarc plugin adds the following dependencies to tasks defined by the Groovy plugin.
check-
Depends on: All CodeNarc tasks, including
codenarcMainandcodenarcTest.
Project layout
The CodeNarc plugin expects the following project layout:
<root>
└── config
└── codenarc (1)
└── codenarc.xml (2)
| 1 | CodeNarc configuration files go here |
| 2 | Primary CodeNarc configuration file |
The default configuration file is resolved relative to the root project directory, so a single config/codenarc/codenarc.xml is shared by all projects in the build unless the config property is overridden.
|
Dependency management
The CodeNarc plugin adds the following dependency configurations:
| Name | Meaning |
|---|---|
|
The CodeNarc libraries to use |
|
If CodeNarc requires a different Groovy version than that used to compile Groovy source, you can supply one using the |
dependencies {
"codenarc"("org.codehaus.groovy:groovy-all:3.0.3")
"codenarc"("org.codenarc:CodeNarc:1.6.1")
}
dependencies {
codenarc 'org.codehaus.groovy:groovy-all:3.0.3'
codenarc 'org.codenarc:CodeNarc:1.6.1'
}
Configuration
The CodeNarc plugin is configured through the CodeNarcExtension (the codenarc {} block). The most commonly used properties and their default values are:
| Property | Description | Gradle default |
|---|---|---|
|
The version of CodeNarc to use. |
|
|
The CodeNarc configuration to use. |
|
|
The format of the generated report. One of |
|
|
The maximum number of priority 1 violations allowed before failing the build. |
|
|
The maximum number of priority 2 violations allowed before failing the build. |
|
|
The maximum number of priority 3 violations allowed before failing the build. |
|
|
The directory where reports are generated. |
|
See the CodeNarcExtension class in the API documentation for the full set of options.