问题
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