Last active
February 6, 2021 19:06
-
-
Save rafayali/73f43adfe3e6511ace8863a64058f361 to your computer and use it in GitHub Desktop.
A gradle function to read properties from a file
This file contains hidden or 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
def getProperty(String filename, String propName) { | |
def propsFile = rootProject.file(filename) | |
if (propsFile.exists()) { | |
def props = new Properties() | |
props.load(new FileInputStream(propsFile)) | |
if (props[propName] != null) { | |
return props[propName] | |
} else { | |
print("No such property " + propName + " in file " + filename) | |
} | |
} else { | |
print(filename + " does not exist!") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample usage inside an android's app module gradle file