CodeNarc - CodeNarc Command Line

##### General

- Home
- Downloads
- Road Map
- Javadocs
- Mailing Lists
- Bug Tracker
- SourceForge Project

##### Running

- Ant Task Usage
- Command-Line
- Run as a Test
- Other Tools/Frameworks

##### Using

- Creating a RuleSet
- Creating a Rule
- Configuring Rules
- Starter RuleSet (All)

##### Report Types

- HTML (HtmlReportWriter)
- XML (XmlReportWriter)
- Text (TextReportWriter)

##### Sample Reports

- Sample HTML Report
- Open Source Projects

##### Rules

- Rule Index
- Basic Rules
- Braces Rules
- Concurrency Rules
- Convention Rules
- Design Rules
- DRY Rules
- Exceptions Rules
- Formatting Rules
- Generic Rules
- Grails Rules
- Groovyism Rules
- Imports Rules
- JDBC Rules
- JUnit Rules
- Logging Rules
- Naming Rules
- Size/Complexity Rules
- Security Rules
- Serialization Rules
- Unnecessary Rules
- Unused Rules

##### Developing

- Developer Guide

##### Project Documentation

- Project Information
- Project Reports

## CodeNarc - Run From Command-Line

CodeNarc can be run from the command-line as a Java application. The `org.codenarc.CodeNarc` class provides the application entry-point.

### CodeNarc Command-Line Parameters

Usage: `java org.codenarc.CodeNarc [OPTIONS]` where OPTIONS are zero or more command-line parameters of the form "`-NAME[=VALUE]`"

All command-line parameters are optional. If no parameters are supplied, CodeNarc runs from the current directory with reasonable defaults, as described below.

Parameter | Description | Example
-basedir=DIR | The base (root) directory for the source code to be analyzed. Defaults to the current directory ("."). | -basedir=src/main/groovy
-includes=PATTERNS | The comma-separated list of Ant-style file patterns specifying files that must be included. Defaults to "**/*.groovy". | -includes=**/*.gr
-excludes=PATTERNS | The comma-separated list of Ant-style file patterns specifying files that must be excluded. No files are excluded when omitted. | -excludes=**/templates/**, **/*Test.*
-rulesetfiles=FILENAMES | The path to the Groovy or XML RuleSet definition files, relative to the classpath. This can be a single file path, or multiple paths separated by commas. Defaults to "rulesets/basic.xml". | -rulesetfiles=rulesets/imports.xml, rulesets/naming.xml
-report=REPORT-TYPE[:FILENAME] | The definition of the report to produce. The option value is of the form `TYPE[:FILENAME]`, where `TYPE` is one of the predefined type names: "html", "xml", "text", "console" or else the fully-qualified class name of a class (accessible on the classpath) that implements the `org.codenarc.report.ReportWriter` interface. And `FILENAME` is the filename (with optional path) of the output report filename. If the report filename is omitted, the default filename for the report type is used ("CodeNarcReport.html" for "html" and "CodeNarcXmlReport.xml" for "xml"). If no report option is specified, default to a single "html" report with the default filename. | -report=html -report=html:MyProject.html -report=xml -report=xml:MyXmlReport.xml -report=org.codenarc.report. HtmlReportWriter
-title=REPORT TITLE | The title description for this analysis; used in the output report(s), if provided. | -title="My Project"
-help | Display the command-line help. If present, this must be the only command-line parameter. | -help

### Executing CodeNarc from the Command-Line

Make sure that the following are included your CLASSPATH:

1. The Groovy jar
2. The CodeNarc jar
3. The Log4J jar
4. The directories containing (or relative to) CodeNarc config files such as "codenarc.properties" or ruleset files.

Here is an example BAT file for running CodeNarc on Windows.

    @set GROOVY_JAR="%GROOVY_HOME%/embeddable/groovy-all-1.5.6.jar"

    @java -classpath %GROOVY_JAR%;lib/CodeNarc-0.5.jar;lib/log4j-1.2.14.jar;lib org.codenarc.CodeNarc %*