Feature request: Allow custom CodeNarc report classes

CodeNarc supports using a custom reporting class to write reports in a user-defined format. For integration with Jenkins, I’d like to do this since a bug in the Jenkins Warnings Plugin precludes use of the XML report. Would it be possible to allow CodeNarcExtension.reportFormat to be set to a custom reporting class?

As a workaround you could use the codenarc ant task and Gradle’s ant integration

The report nested element defines the format and output file for the analysis report.

Attribute Description Required
type The type of the output report. Must be either one of the predefined type names: “html”, “xml”, “text”, “console”, “ide” or else the fully-qualified class name of a class (accessible on the classpath) that implements the org.codenarc.report.ReportWriterinterface. yes

Thanks, @Lance - I’ve tried to get this working but can’t. I’m getting the following error:

> taskdef A class needed by class org.codenarc.ant.CodeNarcTask cannot be found: org/slf4j/LoggerFactory

The relevant parts of my build.gradle are:

dependencies {
    codenarc "org.codenarc:CodeNarc:${codenarcVersion}"
    codenarc "org.codehaus.groovy:groovy-all:${groovyVersion}"
    codenarc "org.codehaus.groovy:groovy-ant:${groovyVersion}"
    codenarc 'org.gmetrics:GMetrics:1.0'
    codenarc 'org.slf4j:slf4j-api:1.7.25'
    codenarc 'org.slf4j:slf4j-simple:1.7.25'
    codenarc files('config/codenarc')
task hello {
    doLast {
        ant.taskdef(name: 'codenarcX',
                classname: 'org.codenarc.ant.CodeNarcTask',
                classpath: configurations.codenarc.asPath)
        ant.codenarcX(ruleSetFiles: 'config/codenarc/ruleset.groovy') {
            report(type: 'JenkinsReportWriter')

Gradle seems to be completely ignoring the slf4j-api dependency.

I’m guessing there’s something screwy with the classpath. Perhaps try:

def printResourcePaths = { config, path ->
   def urls = config.files.collect { it.toURI().toURL()}
   def cl = new URLClassLoader(urls as URL[])
   println "Found $path in $config.name at ${cl.findResources(path)}"
task printStuff {
   doLast {
      printResourcePaths(configurations.codenarc, 'org/slf4j/LoggerFactory.class')
      printResourcePaths(buildscript.configurations.classpath, 'org/slf4j/LoggerFactory.class')

Thanks, @Lance - I’ve parked this work for now, feel free to try and work out what’s going on!
I might be able to get back to this in a few weeks’ time.