Skip to content

Instantly share code, notes, and snippets.

@Jween
Created March 15, 2016 04:02
Show Gist options
  • Save Jween/6f3c06cbbcb06f01dd8f to your computer and use it in GitHub Desktop.
Save Jween/6f3c06cbbcb06f01dd8f to your computer and use it in GitHub Desktop.
Read data from local.properties file in gradle script
//
// 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