Over a million developers have joined DZone.

Gradle CodeNarc Plugin

DZone's Guide to

Gradle CodeNarc Plugin

· Java Zone
Free Resource

Learn how our document data model can map directly to how you program your app, and native database features like secondary indexes, geospatial and text search give you full access to your data. Brought to you in partnership with MongoDB.

After working on Gradle CodeNarc plugin for some time and using it in 3 of my projects, I decided to officially release it last week. This plugin allows to easily run a CodeNarc Groovy code analysis from your Gradle build script.

In the simplest form the plugin can be used as:

apply from: 'https://raw.github.com/evgeny-goldin/gradle-plugins/master/src/main/groovy/CodeNarc.gradle'

which adds new "codenarc" Gradle task. But it is better not to rely on default values of CodeNarc version and RuleSet files which will change every time a newer CodeNarc version is released. Specifying some of parameters makes Gradle builds less vulnerable to CodeNarc updates:

codenarcVersion      = '0.15'
codenarcRuleSetFiles = [ 'codenarc.groovy' ]
apply from: 'https://raw.github.com/evgeny-goldin/gradle-plugins/master/src/main/groovy/CodeNarc.gradle'

As always, examples and documentation are available in the Wiki. Your comments, feedback and bug reports are most welcome!

This is the third Gradle plugin released as of today. Two others are:

  • “About” plugin adds textual “about” file to build artifacts created, linking each binary artifact to the build environment and sources it was created with. The file added contains details about build date and time, last commit made in the project, Java / Gradle versions used for build and some other optional elements like project dependencies, local paths, system and environment variables. If the project was built by Jenkins, TeamCity or Hudson build server then corresponding job details are also added to the file generated.

    This is a simple and powerful way to keep all your artifacts aware of their build context, timestamp, and environment.

  • “Duplicates” plugin locates duplicate libraries in Gradle configurations. Duplicate libraries have different coordinates (group or name) but contain an identically named classes, i.e., classes with identical fully qualified names. One source of possible duplicates are changes done to library coordinates in Maven repositories. When libraries evolve, migrate, grow up and split up they may start naming their artifacts differently. And then having an old and new version of the same library in Gradle configuration causes a duplicate problem.

    Another possible source of duplicate classes in the same configuration are repacking portions of one library in another which may happen from time to time. Whatever reason for duplicate is, this plugin quickly locates all of them and either fails the build or displays a warning.


New Gradle plugins will surely be added later so stay tuned!


From http://evgeny-goldin.com/blog/gradle-codenarc-plugin

Discover when your data grows or your application performance demands increase, MongoDB Atlas allows you to scale out your deployment with an automated sharding process that ensures zero application downtime. Brought to you in partnership with MongoDB.


Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}