Codenarc gradle files themselves

Hi,

does someone have a nice recipe or trick to perform a codenarc check on all gradle files themselves? Or some other sode styel checker for gradle files?

This would ideally rely in some “reflection” of the files included in a build, meaning all build.gradle files (or files named differently but used for the same purpose), and any other file used with “apply from:”. Else some manual crawling for files below the project root.

So the best I could do myself so far was to write a shell-script for linux, like this

#! /usr/bin/env sh
set -e -x
  export GROOVY=/path/to/groovy-all-2.3.3.jar
export CODENARC=/path/to/CodeNarc-0.21.jar
export LOG4J=/path/to/log4j-1.2.17.jar
export CONFIG=/path/to/ruleseDir
  java -cp "$LOG4J:$GROOVY:$CONFIG:$CODENARC" org.codenarc.CodeNarc -includes=**/*.gradle -basedir=. -rulesetfiles=rules.groovy

Needless to say, that is rather ugly. Can this be transformed easily into a gradle task with suitable classpathes, based on the codenarc plugin?

1 Like