The CodeNarc Ant Task is implemented by the org.codenarc.ant.CodeNarcTask class.
| Attribute | Description | Required |
| ruleSetFiles | The paths to the Groovy or XML RuleSet definition files. This can be a single file path, or multiple paths separated by commas. By default, the paths specified are relative to the classpath. But each path may be optionally prefixed by any of the valid java.net.URL prefixes, such as "file:" (to load from a relative or absolute filesystem path), or "http:". |
YES |
| maxPriority1Violations | The maximum number of priority 1 violations allowed before failing the build (throwing a BuildException ). |
NO |
| maxPriority2Violations | The maximum number of priority 2 violations allowed before failing the build (throwing a BuildException ). |
NO |
| maxPriority3Violations | The maximum number of priority 3 violations allowed before failing the build (throwing a BuildException ). |
NO |
The report nested element defines the format and output file for the analysis report. Currently, HTML ("html") is the only supported format.
| Attribute | Description | Required |
| type | The format of the output analysis report. The only valid value is "html" |
Yes |
| toFile | The path and filename for the output report file. | No |
| title | The title for the output report. | No |
At least one fileset nested element is required, and is used to specify the source files that CodeNarc should analyze. This is the standard Ant FileSet , and is quite powerful and flexible. See the Apache Ant Manual for more information on FileSets .
Here is an example Ant XML build file.
<taskdef name="codenarc" classname="org.codenarc.ant.CodeNarcTask"/>
<target name="runCodeNarc">
<codenarc
ruleSetFiles="rulesets/basic.xml,rulesets/exceptions.xml,rulesets/imports.xml"
maxPriority1Violations="0">
<report type="html" toFile="reports/CodeNarcAntReport.html" title="My Sample Code"/>
<fileset dir="src">
<include name="**/*.groovy"/>
</fileset>
</codenarc>
</target>
Things to note: