// 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:

.Using the CodeNarc plugin
====
include::sample[dir="codeQuality/groovy",files="build.gradle[tags=use-codenarc-plugin]"]
include::sample[dir="codeQuality/kotlin",files="build.gradle.kts[tags=use-codenarc-plugin]"]
====

The plugin adds a number of tasks to the project that perform the quality checks when used with the <<groovy_plugin.adoc#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:

`codenarcMain` — link:{groovyDslPath}/org.gradle.api.plugins.quality.CodeNarc.html[CodeNarc]::
+
Runs CodeNarc against the production Java source files.

`codenarcTest` — link:{groovyDslPath}/org.gradle.api.plugins.quality.CodeNarc.html[CodeNarc]::
+
Runs CodeNarc against the test Java source files.

`codenarc__SourceSet__` — link:{groovyDslPath}/org.gradle.api.plugins.quality.CodeNarc.html[CodeNarc]::
+
Runs CodeNarc against the given source set's Java source files.

=== 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 `codenarcMain` and `codenarcTest`.


[[sec:codenarc_project_layout]]
== 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


[[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 link:{groovyDslPath}/org.gradle.api.plugins.quality.CodeNarcExtension.html[CodeNarcExtension] class in the API documentation.
