I am trying to generate Codenarc reports for my Gradle Groovy project and publish them in Jenkins.
I successfully configured my Gradle project to produce Codenarc reports with:
build.gradle
apply plugin: 'codenarc'
...
dependencies {
codenarc 'org.codenarc:CodeNarc:0.21'
...
}
codenarc {
configFile = file('config/codenarc/codenarc.groovy')
// sourceSets = [project.sourceSets.main] // run codenarc on production sources only
ignoreFailures = true // Let the build finish even though there are code warnings
reportFormat = 'xml'
reportsDir = new File("build/reports/codenarc")
}
config/codenarc/codenarc.groovy
// Read and choose rules here: http://codenarc.sourceforge.net/codenarc-rule-index.html
ruleset {
ruleset('rulesets/basic.xml')
}
I also set up a job on Jenkins with the Violations plugin, but when the Violations report is generated it does not show the actual code violations. It just shows statistics, and a blank page if I press the groovy file with violations.
I have Grails projects with the Codenarc plugin, which shows up with full code snippets in the violations report, so I am guessing there is something wrong with my Codenarc setup in Gradle?
Any help or suggestions are very welcome!
Edit: If relevant, the resulting Codenarc XML looks like this:
<?xml version='1.0'?>
<CodeNarc url='http://www.codenarc.org' version='0.21'>
<Report timestamp='07-10-2014 15:31:18'/>
<Project title=''>
<SourceDirectory>src\groovy</SourceDirectory>
</Project>
<PackageSummary totalFiles='124' filesWithViolations='118' priority1='0' priority2='156'
priority3='143'></PackageSummary>
<Package path='testmodel' totalFiles='124' filesWithViolations='118' priority1='0' priority2='156'
priority3='143'></Package>
<Package path='testmodel/begivenheder' totalFiles='31' filesWithViolations='30' priority1='0' priority2='32'
priority3='17'>
<File name='AbstraktTest.groovy'>
<Violation ruleName='ClassJavadoc' priority='2' lineNumber='5'>
<SourceLine><![CDATA[@CompileStatic]]></SourceLine>
<Message><![CDATA[Class testmodel.begivenheder.AbstraktAendring missing JavaDoc]]></Message>
</Violation>
...
</File>
</Package>
<Rules>
<Rule name='AbcMetric'>
<Description>
<![CDATA[Checks the ABC size metric for methods/classes. A method (or "closure field") with an ABC score greater than the maxMethodAbcScore property (60) causes a violation. Likewise, a class that has an (average method) ABC score greater than the maxClassAverageMethodAbcScore property (60) causes a violation.]]></Description>
</Rule>
...
</Rules>
</CodeNarc>
Consider using HTML Publisher plugin You can configure report parameters in job configuration Post-build Actions or if you are using pipeline, add these lines to your Jenkinsfile:
node('slaveName') {
// git, build, test, stages omitted
stage('Publish') {
echo 'Publish Codenarc report'
publishHTML(
target: [
allowMissing : false,
alwaysLinkToLastBuild: false,
keepAll : true,
reportDir : 'target/site',
reportFiles : 'codenarc.html',
reportName : "Codenarc Report"
]
)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With