save env in project.env with gradle so it can be reused

This commit is contained in:
Pedro Belo 2016-02-23 16:25:35 -08:00
parent 22236cf33d
commit 32d929e234
1 changed files with 5 additions and 2 deletions

View File

@ -1,18 +1,21 @@
def readDotEnv = {
def env = [:]
def envFile = System.env['ENVFILE'] ?: "$project.rootDir/../.env"
println("Reading env from: $envFile")
new File(envFile).eachLine { line ->
def (key, val) = line.tokenize('=')
if (key && val) {
env.put(key, val)
}
}
env
project.ext.set("env", env)
}
readDotEnv()
android {
defaultConfig {
readDotEnv().each { k, v ->
project.env.each { k, v ->
buildConfigField "String", k, "\"$v\""
resValue "string", k, "\"$v\""
}