Codenarc tries to analyze Grails Groovy templates when they are integrated into the project.
This leads to false positive errors:
Im my case Codenarc is executed by sonar-runner:
11:20:06.509 INFO - Executing CodeNarc
11:20:06.883 INFO - Loaded properties file in 24ms; 322 rules
11:20:06.908 INFO - Loading ruleset from [file:/testapp/./.sonar/codenarc/profile.xml]
11:20:07.303 INFO - RuleSet configuration properties file [codenarc.properties] not found.
11:20:09.737 WARN - Compilation failed for [SourceFile[/testapp/./src/templates/artifacts/Controller.groovy]].
11:20:09.743 INFO - Compilation failed because of [org.codehaus.groovy.control.MultipleCompilationErrorsException] with message: [startup failed:
None: 1: expecting "interface", found 'class' @ line 1, column 19.
@artifact.package@class @artifact.name@ {
^
1 error
]
11:20:09.750 WARN - Compilation failed for [SourceFile[/testapp/./src/templates/artifacts/DomainClass.groovy]].
11:20:09.750 INFO - Compilation failed because of [org.codehaus.groovy.control.MultipleCompilationErrorsException] with message: [startup failed:
None: 1: expecting "interface", found 'class' @ line 1, column 19.
@artifact.package@class @artifact.name@ {
^
1 error
]
...and many more
To test it, simply create a Grails (2.4.4) project and call "grails install-templates" to integrate them into the project. Then execute Codenarc on it.
I take it you are not using the Grails CodeNarc plugin, but are rather using Sonar. I'm not sure how to configure that to ignore the /src/templates directory. That would not be something configured within base CodeNarc. CodeNarc does provide generic configuration mechanisms, but I'm not sure how Sonar uses or exposes those.
Are you using the Sonar Groovy Plugin?
http://docs.sonarqube.org/display/SONAR/Groovy+Plugin
Thats correct, I use the Sonar Groovy Plugin and sonar-runner within Jenkins as a Post build standalone task. This way (on Sonar 5.0), multi-language tests are performed out of the box dependent on the plugins installed in Sonar, so we can test Groovy, Java, Javascript, XML and CSS files automatically.
I played around with the sonar.sources and sonar.exclusions properties and figured out that sonar.exclusions seem to be ignored by codenarc.
So using
sonar.sources=src/java,src/groovy,grails-app/services,grails-app/controllers,grails-app/domain,grails-app/taglib,grails-app/assets, grails-app/conf
did the trick. This way, you can avoid the template compilation errors.
Disadvantage is, that you need to add new source directories and files to sonar.sources manually.