user_9090
user_9090

Reputation: 1984

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

Upvotes: 2

Views: 6521

Answers (1)

smac89
smac89

Reputation: 43234

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.

Upvotes: 3

Related Questions