gradle / gradle

Adaptable, fast automation for all
https://gradle.org
Apache License 2.0
16.65k stars 4.66k forks source link

CodeNarc plugin - display report on console only if violations found #12663

Open szpak opened 4 years ago

szpak commented 4 years ago

Expected Behavior

When executed without violations CodeNarc plugin generates only file/html reports (if enabled) - no output from CodeNarc tasks. If violations are found then they are reported on console (to do not have to look into files, also on a CI server).

Current Behavior

User has to choose to display also (usually) meaningless output on the executions without violations to see (without reading the report) also violations they accidentally occur.

Context

Unnecessary cluttered console or harder to get information about errors. User should be able to decide to only use console output on errors.

Tested with Gradle 6.3.

bjornvester commented 4 years ago

As a CodeNarc user, I would like this behaviour as well. I currently achieve it with the following build script (Groovy DSL):

tasks.withType(CodeNarc) { codeNarcTask ->
    reports {
        text.enabled = true
        html.enabled = true
    }
    codeNarcTask.finalizedBy(project.task("print${codeNarcTask.name.capitalize()}") {
        onlyIf {
            codeNarcTask.state.failure != null
        }
        doLast {
            logger.warn("\n****************************** CODE NARC ******************************")
            logger.warn(codeNarcTask.reports.text.destination.text.trim())
            logger.warn("****************************** CODE NARC ******************************\n")
        }
    })
}
stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. If you're interested in how we try to keep the backlog in a healthy state, please read our blog post on how we refine our backlog. If you feel this is something you could contribute, please have a look at our Contributor Guide. Thank you for your contribution.

szpak commented 2 years ago

It would be still useful to have it available out of the box.