Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »


Groovy/Grails CodeNarc - GMetrics Bridge


Scott Kessler




Under Development (alpha testing)



Download Sources


Download JAR


Version Information









Description / Features

This plugin will consume output from CodeNarc, which produces violation information, and GMetrics, which produces metric information, both for Groovy (with some Grails specific violation information) and pull the data into Sonar.

Usage and installation


You will need to setup CodeNarc and Gmetrics for your Grails application. Most of this is done by editing the following files:

  • Config.groovy
  • Pom.xml

Details on installing the appropriate plugins and how to edit these files is explained  in the sections below.

Basically once everything is setup you’ll be running the following commands(assuming you are using Maven):

                mvn grails:exec --Dcommand=codenarc

                mvn compile

                mvn sonar:sonar

At which point your application metrics should be available within your Sonar instance.


CoeNarc is used to report on violations in your code. Typical violations are things like an empty else clause, or an import that is never used.  There are many more violation types but you get the general idea.

Install codenarc plugin

                grails install-plugin codenarc  (0.4 or 0.5 . Not testing with anything above that yet)


                mvn grails:install-plugin --DpluginName=codenarc

Note that I have had the problem where a Maven install “mvn” does NOT update the file with the codenarc plugin. In that case I have also had to do a “grails install-plugin…” or alternately just edit the file to add the appropriate current codenarc version.

Add report name/type to your Config.groovy


codenarc.reportType = ‘xml’  (the Grails plugin 0.3 only recognizes HTML, >0.4 also recognizes xml & text. This plugin requires the xml output.)

codenarc.reportTitle=’YOUR TITLE’

Run codenarc against your project:

                grails codenarc

or  since you are using Maven you should use

                mvn grails:exec --Dcommand=codenarc


CodeNarc is known to not run properly as a grails plugin if your project includes an XML library that includes an older version of some of the XML Constants. For example the stacks.jar in Xfire. CodeNarc will run properly from the command line using a bat file as it picks up the proper classes, but when you run it using “grails codenarc” it tries to start up Grails and that in turn finds the improper library in your app. and it doesn’t run.

  • No labels