Grails "war" 调用未将额外属性传递给 Gradle
Grails "war" invocation not passing extra properties to Gradle
当调用 "grails war" 命令时,grails.env 属性 被传递给 Gradle,但是我用 -D 定义的任何其他 属性 是未通过。
我已经验证 Gradle 将获得属性,我可以使用 "gradle -Dgrails.env=development -Dfoo.bar=blech"
这样的命令打印它们
使用此命令调用 grails:
grails -Dgrails.env=开发-Dfoo.bar=blech war
build.gradle:
ext {
currentBuildEnvironment = System.properties['grails.env']
println "Current build environment is ${currentBuildEnvironment}"
fooBar = System.properties['foo.bar']
println "fooBar: ${fooBar}"
}
这为 currentBuildEnvironment 正确打印 "development",但为 fooBar 打印 null。
默认情况下,您不允许将自定义属性传递给 grails
命令。
来自Grails Command Line documentation:
The grails command is a front to a gradle invocation, because of this
there can be unexpected side-effects. For example, when executing
grails -Dapp.foo=bar run-app the app.foo system property won’t be
available to your application. This is because bootRun in your
build.gradle configures the system properties. To make this work you
can simply append all System.properties to bootRun in build.gradle
like:
bootRun{
systemProperties System.properties // Please note not to use '=', because this will > override all configured systemProperties. This will append them.
}
并在您的脚本中使用以获取任何自定义属性:
ext {
fooBar = bootRun.systemProperties['foo.bar']
println "fooBar: ${fooBar}"
}
此外,您可以根据前缀传递一组有限的属性:
bootRun{
systemProperties System.properties.inject([:]){acc,item-> item.key.startsWith('foo.')?acc << [(item.key.substring('foo.'.length())):item.value]:acc }
}
并且只获取 属性 没有前缀:
ext {
fooBar = bootRun.systemProperties['bar']
println "fooBar: ${fooBar}"
}
您可以在 bootRun
部分中使用传递属性:
systemProperties System.properties.inject([:]){acc,item-> item.key.startsWith('foo.')?acc << [(item.key):item.value]:acc }
将拥有从 'foo' 开始且后缀为:
的所有属性
bootRun.systemProperties['foo.bar']
当调用 "grails war" 命令时,grails.env 属性 被传递给 Gradle,但是我用 -D 定义的任何其他 属性 是未通过。
我已经验证 Gradle 将获得属性,我可以使用 "gradle -Dgrails.env=development -Dfoo.bar=blech"
这样的命令打印它们使用此命令调用 grails:
grails -Dgrails.env=开发-Dfoo.bar=blech war build.gradle:
ext {
currentBuildEnvironment = System.properties['grails.env']
println "Current build environment is ${currentBuildEnvironment}"
fooBar = System.properties['foo.bar']
println "fooBar: ${fooBar}"
}
这为 currentBuildEnvironment 正确打印 "development",但为 fooBar 打印 null。
默认情况下,您不允许将自定义属性传递给 grails
命令。
来自Grails Command Line documentation:
The grails command is a front to a gradle invocation, because of this there can be unexpected side-effects. For example, when executing grails -Dapp.foo=bar run-app the app.foo system property won’t be available to your application. This is because bootRun in your build.gradle configures the system properties. To make this work you can simply append all System.properties to bootRun in build.gradle like:
bootRun{ systemProperties System.properties // Please note not to use '=', because this will > override all configured systemProperties. This will append them. }
并在您的脚本中使用以获取任何自定义属性:
ext {
fooBar = bootRun.systemProperties['foo.bar']
println "fooBar: ${fooBar}"
}
此外,您可以根据前缀传递一组有限的属性:
bootRun{
systemProperties System.properties.inject([:]){acc,item-> item.key.startsWith('foo.')?acc << [(item.key.substring('foo.'.length())):item.value]:acc }
}
并且只获取 属性 没有前缀:
ext {
fooBar = bootRun.systemProperties['bar']
println "fooBar: ${fooBar}"
}
您可以在 bootRun
部分中使用传递属性:
systemProperties System.properties.inject([:]){acc,item-> item.key.startsWith('foo.')?acc << [(item.key):item.value]:acc }
将拥有从 'foo' 开始且后缀为:
的所有属性bootRun.systemProperties['foo.bar']