Codenarc Plugin Fails if I choose reportFormat = xml

I’m using the Codenarc plugin with my new project. However, I’m now setting it up on Jenkins to use with the Jenkins Violations plugin (like I do with Grails/Codenarc/Jenkins). To do that, I need both html and xml output to come out at the same time, the way that Cobertura works (for both Grails and Gradle). It appears that the Gradle Codenarc plugin only allows one output at a time. I thought I would work on the issue one problem at a time. So, I started to set it up to use xml output format. When I did that, codenarc failed. Here is my configuration:

project.ext {

codenarcReportFormat = ‘xml’ //NOTE: If I put html here, it works fine - switching to XML makes it fail

}

Later in the build:

codenarc {

reportFormat = “${project.ext.codenarcReportFormat}”

configFile = new File("${project.projectDir}/config/codenarc/rules.groovy")

}

I’ve included a chunk of the stack trace below. It seems odd that html versus xml format can make it work or not work. That is certainly not the case when running the same codenarc under Grails and Jenkins.

Mike

Caused by: : groovy.lang.MissingPropertyException: No such property: maxMethodComplexity for class: org.codenarc.rule.size.AbcMetricRule

at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:116)

at org.gradle.api.internal.project.ant.BasicAntBuilder.nodeCompleted(BasicAntBuilder.java:71)

at org.gradle.api.internal.project.AntBuilderDelegate.nodeCompleted(DefaultIsolatedAntBuilder.groovy:172)

at org.gradle.api.plugins.quality.CodeNarc$_run_closure2.doCall(CodeNarc.groovy:130)

at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:58)

at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:133)

at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:94)

at org.gradle.util.ConfigureUtil$configure.call(Unknown Source)

at org.gradle.api.internal.project.DefaultIsolatedAntBuilder.execute(DefaultIsolatedAntBuilder.groovy:112)

at org.gradle.api.internal.project.IsolatedAntBuilder$execute.call(Unknown Source)

at org.gradle.api.plugins.quality.CodeNarc.run(CodeNarc.groovy:127)

at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:248)

at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:136)

at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147)

at org.gradle.api.plugins.quality.CodeNarc_Decorated.invokeMethod(Unknown Source)

at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:248)

at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:136)

at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147)

at org.gradle.api.plugins.quality.CodeNarc_Decorated.invokeMethod(Unknown Source)

at org.gradle.util.ReflectionUtil.invoke(ReflectionUtil.groovy:23)

at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:220)

at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:213)

at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:202)

at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:530)

at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:513)

at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)

at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)

… 50 more Caused by: groovy.lang.MissingPropertyException: No such property: maxMethodComplexity for class: org.codenarc.rule.size.AbcMetricRule

at SimpleTemplateScript1.run(SimpleTemplateScript1.groovy:1)

at org.codenarc.report.AbstractReportWriter.substituteMessageParametersIfPresent(AbstractReportWriter.groovy:114)

at org.codenarc.report.AbstractReportWriter.this$2$substituteMessageParametersIfPresent(AbstractReportWriter.groovy)

at org.codenarc.report.AbstractReportWriter$this$2$substituteMessageParametersIfPresent.callCurrent(Unknown Source)

at org.codenarc.report.AbstractReportWriter.getDescriptionForRule(AbstractReportWriter.groovy:107)

at org.codenarc.report.XmlReportWriter$_buildRulesElement_closure9_closure20_closure21.doCall(XmlReportWriter.groovy:148)

at org.codenarc.report.XmlReportWriter$_buildRulesElement_closure9_closure20.doCall(XmlReportWriter.groovy:147)

at org.codenarc.report.XmlReportWriter$_buildRulesElement_closure9.doCall(XmlReportWriter.groovy:146)

at org.codenarc.report.XmlReportWriter$_writeReport_closure1_closure11.doCall(XmlReportWriter.groovy:48)

at org.codenarc.report.XmlReportWriter$_writeReport_closure1.doCall(XmlReportWriter.groovy:44)

at org.codenarc.report.XmlReportWriter.writeReport(XmlReportWriter.groovy:51)

at org.codenarc.report.AbstractReportWriter$_writeReportToFile_closure3.doCall(AbstractReportWriter.groovy:82)

at org.codenarc.report.AbstractReportWriter.writeReportToFile(AbstractReportWriter.groovy:81)

at org.codenarc.report.AbstractReportWriter.this$2$writeReportToFile(AbstractReportWriter.groovy)

at org.codenarc.report.AbstractReportWriter$this$2$writeReportToFile.callCurrent(Unknown Source)

at org.codenarc.report.AbstractReportWriter.writeReport(AbstractReportWriter.groovy:68)

at org.codenarc.report.ReportWriter$writeReport.call(Unknown Source)

at org.codenarc.CodeNarcRunner$_execute_closure1.doCall(CodeNarcRunner.groovy:79)

at org.codenarc.CodeNarcRunner.execute(CodeNarcRunner.groovy:78)

at org.codenarc.CodeNarcRunner$execute.call(Unknown Source)

at org.codenarc.ant.CodeNarcTask.execute(CodeNarcTask.groovy:85)

at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)

at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)

… 76 more

You can enable/disable the report type like this:

tasks.withType(CodeNarc) {
    reports {
        xml.enabled = true
        html.enabled = true
    }
}
2 Likes