Pass env variables to gradle.properties

强颜欢笑 提交于 2021-02-05 11:31:07

问题


I have a property set like this:

url=localhost:3206

Is there a way to specifiy this like below instead:

url=${hostname}:3206

回答1:


I don't think gradle.properties supports interpolation. However, I would suggest an alternative means to accomplishing this:

Have the following in your gradle.properties:

hostname=localhost
port=3206

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

Now when you run your project, gradle will pick up the environmental variables and replace the ones in gradle.properties with these.



来源:https://stackoverflow.com/questions/61577070/pass-env-variables-to-gradle-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!