How to use CodeNarc for Gradle build scripts?

What is the best way to use a static analysis tool (like CodeNarc) to check the “well-formattedness” of the Gradle build scripts themselves?

Background: We are currently migrating from Ant to a Gradle multi-project build. Having had some issues with bad formatting in our Ant scripts (indenting, tabs vs spaces, …), we would like to start clean from the start by having the build fail when the build scripts don’t fulfill the formatting rules. As we use a multi-project build (and buildSrc), at best all relevant scripts should be checked automatically (without having to scan the whole repository for .gradle files).

1 Like