我正在尝试使用像这样的config slurper解析一个groovy文件。
fileContents = '''deployment {
deployTo('dev') {
test = me
}
}'''
def config = new ConfigSlurper().parse(fileContents)
上面的代码之所以起作用,是因为decloyto('dev')只是接受字符串。但是我在其中添加了一个额外的参数,它在此例外失败:
fileContents = '''deployment {
deployTo('dev','qa') {
test = me
}
}'''
def config = new ConfigSlurper().parse(fileContents)
它失败了以下例外:
抓取:groovy.lang.missingmethodexception:没有方法的签名:groovy.util.configslurper $ _parse_close_closure5.deployto()适用于参数类型:_CLOUSE10)值:[dev,postrun,script15047332444444444444444444444439770645 $ _run_closure3 $ _cluse10@6b8ca3c8]
有没有办法在模块中读取带有额外args的配置文件?
您几乎在那里。为了使用值列表,请进行以下更改。
来自:
deployTo('dev','qa')
to:
deployTo(['dev','qa'])
是:
def fileContents = '''deployment { deployTo(['dev','qa']) { test = me } }'''
def config = new ConfigSlurper().parse(fileContents)