Pass env variables to gradle.properties

后端 未结 1 1148
孤街浪徒
孤街浪徒 2021-01-29 01:51

I have a property set like this:

url=localhost:3206

Is there a way to specifiy this like below instead:

url=${hostname}:3206


        
相关标签:
1条回答
  • 2021-01-29 02:18

    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.

    0 讨论(0)
提交回复
热议问题