Gradle 3.4:使用ConfigSlurper构建配置文件
我在Gradle 3.4:使用ConfigSlurper构建配置文件,gradle,groovy,build,Gradle,Groovy,Build,我在build.gradle中有以下任务,并根据环境尝试从config.groovy获取wsdlURL值 loadConfiguration() task printProps << { println "WSDLURL: $config.wsdlURL" } def loadConfiguration() { def environment = hasProperty('env') ? env : 'dev' System.setProperty('e
build.gradle
中有以下任务,并根据环境尝试从config.groovy
获取wsdlURL
值
loadConfiguration()
task printProps << {
println "WSDLURL: $config.wsdlURL"
}
def loadConfiguration() {
def environment = hasProperty('env') ? env : 'dev'
System.setProperty('environment', environment)
println "Environment is set to $environment"
def configFile = file('config.groovy')
def config = new ConfigSlurper(environment).parse(configFile.toURI().toURL())
System.setProperty('config', config) \\line 52
}
当我运行gradle-q-Penv=prod printProps
命令时,它失败了,错误如下
Environment is set to prod
FAILURE: Build failed with an exception.
* Where:
Build file 'build.gradle' line: 52
* What went wrong:
A problem occurred evaluating root project 'SignService'.
> No signature of method: static java.lang.System.setProperty() is applicable fo
r argument types: (java.lang.String, groovy.util.ConfigObject) values: [config,
[wsdlURL:https://prod.com/ts/svs.asmx?wsdl]]
Possible solutions: setProperty(java.lang.String, java.lang.String), getProperty
(java.lang.String), getProperty(java.lang.String, java.lang.String), hasProperty
(java.lang.String), getProperties(), getProperties()
下面是我的环境细节
------------------------------------------------------------
Gradle 3.4
------------------------------------------------------------
Build time: 2017-02-20 14:49:26 UTC
Revision: 73f32d68824582945f5ac1810600e8d87794c3d4
Groovy: 2.4.7
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_40 (Oracle Corporation 25.40-b25)
OS: Windows 7 6.1 amd64
看起来gradle无法将groovy对象设置为系统属性,有人能帮我修复吗?错误消息非常清楚 需要两个
String
参数,但您正在传递一个String
和一个ConfigObject
也许你想
System.properties['config'] = config
或
System.properties['config'] = config
System.properties.put('config', config)