// Copyright 2017 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

[[codenarc_plugin]]
== The CodeNarc Plugin

The CodeNarc plugin performs quality checks on your project's Groovy source files using http://codenarc.sourceforge.net/index.html[CodeNarc] and generates reports from these checks.


[[sec:codenarc_usage]]
=== Usage

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

++++
<sample id="useCodeNarcPlugin" dir="codeQuality" title="Using the CodeNarc plugin">
            <sourcefile file="build.gradle" snippet="use-codenarc-plugin"/>
        </sample>
++++

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

[[sec:codenarc_tasks]]
=== Tasks

The CodeNarc plugin adds the following tasks to the project:

.CodeNarc plugin - tasks
[cols="a,a,a,a", options="header"]
|===
| Task name
| Depends on
| Type
| Description

| `codenarcMain`
| -
| api:org.gradle.api.plugins.quality.CodeNarc[]
| Runs CodeNarc against the production Groovy source files.

| `codenarcTest`
| -
| api:org.gradle.api.plugins.quality.CodeNarc[]
| Runs CodeNarc against the test Groovy source files.

| `codenarc__SourceSet__`
| -
| api:org.gradle.api.plugins.quality.CodeNarc[]
| 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.

.CodeNarc plugin - additional task dependencies
[cols="a,a", options="header"]
|===
| Task name
| Depends on
| `check`
| All CodeNarc tasks, including `codenarcMain` and `codenarcTest`.
|===


[[sec:codenarc_project_layout]]
=== Project layout

The CodeNarc plugin expects the following project layout:

.CodeNarc plugin - project layout
[cols="a,a", options="header"]
|===
| File
| Meaning

| `config/codenarc/codenarc.xml`
| CodeNarc configuration file
|===


[[sec:codenarc_dependency_management]]
=== Dependency management

The CodeNarc plugin adds the following dependency configurations:

.CodeNarc plugin - dependency configurations
[cols="a,a", options="header"]
|===
| Name
| Meaning

| `codenarc`
| The CodeNarc libraries to use
|===


[[sec:codenarc_configuration]]
=== Configuration

See the api:org.gradle.api.plugins.quality.CodeNarcExtension[] class in the API documentation.
