Dark theme | Light theme

January 17, 2011

Gradle Goodness: Don't Let CodeNarc Violations Fail the Build

With the code-quality plugin for Groovy project we use CodeNarc to check our code. By default we are not allowed to have any violations in our code, because if there is a violation the Gradle build will stop with a failure. If we don't want to our build to fail, because of code violations, we can set the property ignoreFailures to true for the CodeNarc task.

The code-quality plugin adds two CodeNarc tasks to our project: codenarcMain and codenarcTest. We can simply set the property ignoreFailures for these tasks:

apply plugin: 'code-quality'

[codenarcMain, codenarcTest]*.ignoreFailures = true

We can also search for all tasks of type CodeNarc and set the ignoreFailures property. This is useful if we added new tasks of type CodeNarc to our project and want to change the property of all these tasks:

apply plugin: 'code-quality'

tasks.withType(CodeNarc).allTasks { codeNarcTask ->
    codeNarcTask.ignoreFailures = true