Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate multiple report types using CodeNarc in Gradle

I want to generate both HTML and console report in CodeNarc in Gradle.

My build.gradle:

apply plugin: 'codenarc'
...
codenarc {
    toolVersion = '0.24.1'
    configFile = file('config/codenarc/codenarc.groovy')
    reportFormat = 'html'
}

This works fine, but I'd like also to have report displayed on console, as right now only link to HTML is displayed there. How can I request multiple report types?

like image 448
Michal Kordas Avatar asked Feb 16 '26 21:02

Michal Kordas


2 Answers

Instead of running a second task to generate another report, you could make the following change to add another report format. Then grab one of the files and write it to the console. (You could just grab the HTML or XML report and write that to the console, but it may be hard to read without some formatting.)

Note: The reports closure will get you reports in different formats. The doLast will print the output of one of those reports to the console. If you do not need the console output, you can remove the doLast closure.

I would suggest changing your task like this:

task codenarcConsoleReport {
    doLast {
        println file("${codenarc.reportsDir}/main.txt").text
    }
}
codenarcMain {
    finalizedBy codenarcConsoleReport
    reports {
        text.enabled = true
        html.enabled = true
        xml {
            enabled =  true
            destination = file("${codenarc.reportsDir}/customFileName.xml")
        }
    }
}

Note: This will not cause your task to run twice.

like image 67
LeslieV Avatar answered Feb 19 '26 22:02

LeslieV


In newer versions of Gradle (7+) I get a deprecation warning on:

reports {
    html.enabled = true
    xml.enabled = true
}

The format has changed to (for enabling html and xml reports)

reports {
    html.required = true
    xml.required = true
}
like image 21
dauer Avatar answered Feb 19 '26 23:02

dauer