Created
March 15, 2016 04:02
-
-
Save Jween/6f3c06cbbcb06f01dd8f to your computer and use it in GitHub Desktop.
Read data from local.properties file in gradle script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// read bintray user and api key form gitignored local.properties file | |
// | |
def FILE_LOCAL_PROPERTIES = "local.properties" | |
Properties localProp = new Properties() | |
def getFileInDir = { dir -> | |
File ret = new File("$dir$File.separator$FILE_LOCAL_PROPERTIES") | |
ret?.exists() ? ret : null | |
} | |
def rootLocalPropFile = getFileInDir(project.rootDir) | |
if (rootLocalPropFile) { | |
localProp.load(rootLocalPropFile.newDataInputStream()) | |
} | |
def localPropFile = getFileInDir(project.projectDir) | |
if (localPropFile) { | |
Properties tmpProp = new Properties() | |
tmpProp.load(localPropFile.newDataInputStream()) | |
localProp.putAll(tmpProp) | |
} | |
def propLocal = { localProp?.get it } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment