将环境变量传递给gradle.properties [英] Pass env variables to gradle.properties
问题描述
我有一个这样的属性集:
I have a property set like this:
url=localhost:3206
有没有一种方法可以像下面这样指定:
Is there a way to specifiy this like below instead:
url=${hostname}:3206
推荐答案
我不认为gradle.properties支持插值.但是,我建议您采用另一种方法来完成此任务:
I don't think gradle.properties supports interpolation. However, I would suggest an alternative means to accomplishing this:
在gradle.properties中具有以下内容:
Have the following in your gradle.properties:
hostname=localhost
port=3206
在build.gradle中的某处,执行以下操作:
Somewhere in your build.gradle, do the following:
beforeEvaluate {
ext.url = "$hostname:$port"
}
要配置主机名或端口,您需要几个选项.我更喜欢使用项目环境变量,例如:
To configure the hostname or port, you have several options. I prefer using project environmental variables like:
ORG_GRADLE_PROJECT_hostname=0.0.0.0
ORG_GRADLE_PROJECT_port=4321
现在,当您运行项目时,gradle将拾取环境变量,并用这些变量替换gradle.properties中的那些变量.
Now when you run your project, gradle will pick up the environmental variables and replace the ones in gradle.properties with these.
这篇关于将环境变量传递给gradle.properties的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!