I am using codenarc 1.4 with gradle to test groovy code in a Jenkins shared library, but when running it outputs errors saying it was unable to resolve groovy.lang.Closure
though this doesn't seem to prevent the checks being run.
An example of the code that's hitting the problem is
interface IStepExecutor {
int sh(String command)
void dir(String path, Closure commands)
...
when codenarc is run the following error is produced:
file:/.../IStepExecutor.groovy: 8: unable to resolve class Closure
@ line 8, column 27.
void dir(String path, Closure commands)
^
The codenarc parts of my gradle config is as follows:
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.5.7'
testCompile "org.spockframework:spock-core:1.3-groovy-2.5"
}
codenarc {
toolVersion = "1.4"
}
codenarcMain {
configFile = file("config/codenarc/CodeNarcMain.groovy")
source = 'src'
compilationClasspath += files('src/')
}
codenarcTest {
configFile = file("config/codenarc/CodeNarcMain.groovy")
source = 'src'
compilationClasspath += files('src/')
}
I can stop the error messages by adding an import groovy.lang.Closure
but that causes the UnnecessaryGroovyImport
rule to error. Is there a way to prevent these errors being reported without removing the UnnecessaryGroovyImport
rule?