chrismair / GrailsCodeNarcPlugin

Grails CodeNarc plugin
Apache License 2.0
10 stars 5 forks source link

Support for Grails 3.x? #8

Closed chrismair closed 4 years ago

chrismair commented 8 years ago

This is a carryover and response to issue GPCODENARC-46 on jira.grails.org (which was since shutdown), asking about support for Grails 3.x.

As documented at https://github.com/grails/grails-core/wiki/Grails-3-Priority-Upgrade-Plugins, the Grails CodeNarc Plugin has been "replaced" by the Gradle CodeNarc plugin (https://docs.gradle.org/current/userguide/codenarc_plugin.html) for Grails 3.x and beyond.

I agree that the Gradle plugin documentation is not terribly easy to use; it expects a good bit of Gradle knowledge/experience.

I was able to get the Gradle CodeNarc plugin working with Grails 3.x.

------------------------------------------------------------
Gradle 2.12
------------------------------------------------------------
| Grails Version: 3.1.4
| Groovy Version: 2.4.6
| JVM Version: 1.7.0_51

I added this to build.gradle:

apply plugin:"codenarc"

codenarc {
  config = resources.text.fromFile('codenarc-ruleset.groovy')
}

I added a new “codenarc-ruleset.groovy” file in the project root folder (as an example; customize for yourself):

ruleset {
    ruleset('rulesets/basic.xml')
    ruleset('rulesets/groovyism.xml')
    ruleset('rulesets/naming.xml')
    ruleset('rulesets/unused.xml')
    ruleset('rulesets/unnecessary.xml')
}

And then executed: gradle codenarcMain

mburak commented 7 years ago

@chrismair Do you know where to add the codenarc.properties in the Grails 3 project? I tried adding it in different places but it doesn't seem to be reading it.

chrismair commented 7 years ago

I'll try and take a look.

chrismair commented 7 years ago

I was able to specify the location of the "codenarc.properties" file by setting the "codenarc.properties.file" system property to a file: URL, e.g.: gradle codenarcMain -Dcodenarc.properties.file=file:codenarc.properties