我正在使用 codenarc 1.4 和 gradle 来测试 Jenkins 共享库中的 groovy 代码,但是在运行时输出错误,表示无法解析,groovy.lang.Closure尽管这似乎并没有阻止运行检查。
遇到问题的代码示例是
interface IStepExecutor {
int sh(String command)
void dir(String path, Closure commands)
...
Run Code Online (Sandbox Code Playgroud)
当 codenarc 运行时,会产生以下错误:
file:/.../IStepExecutor.groovy: 8: unable to resolve class Closure
@ line 8, column 27.
void dir(String path, Closure commands)
^
Run Code Online (Sandbox Code Playgroud)
我的 gradle 配置的 codenarc 部分如下:
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 = …Run Code Online (Sandbox Code Playgroud)