Gradle CodeNarc plugin doesn't use correct version of Groovy

This issue has manifested for me with the Gradle CodeNarc plugin reporting compilation failures for classes that use the multicatch feature introduced in Groovy 2.0. I first filed a ticket with the CodeNarc project, but now believe it to be a limitation of the Gradle plugin.

Unless it’s somehow happening magically in the injection of the IsolatedAntBuilder, my belief is that the IsolatedAntBuilder used to run CodeNarc’s ant task is using the default (the version of Groovy that Gradle is using). My expectation is that instead, it should use the version of Groovy that was declared for the configuration that is being reported against. For example, if the main and test configurations have different versions of Groovy, the codenarcMain and codenarcTest tasks should use those different versions.

If this sounds sensible, I’d be happy to work on a pull request in this direction.

This has been fixed in 2.2: http://gradle.org/docs/2.2/release-notes#codenarc-plugin-groovy-version-changes

One minor callout: the fix that was implemented primarily allows configuring the Groovy version used by Codenarc as part of the Codenarc configuration, NOT Codenarc automatically using the Groovy version used by the sourceset. For example, if you have two sourcesets that compile against different versions of Groovy, the plugin doesn’t automatically handle that. You’d need to set the codenarcClasspath property of the individual per-sourceset Codenarc tasks.