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?
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.
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
}
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