Created
January 11, 2021 06:39
-
-
Save YuanLiou/b851eb85018ef01e103ffaffb090fc35 to your computer and use it in GitHub Desktop.
how to apply local.properties to project
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
fun Project.getLocalOrDefaultProperties(): Map<String, Any?> { | |
return getEnvOrDefaultProperties("local.properties") | |
} | |
private fun Project.getEnvOrDefaultProperties(path: String): Map<String, Any?> { | |
return rootProject.file(path) | |
.takeIf { it.canRead() } | |
?.let { readProperties(it).toMap() as Map<String, Any?> } | |
?: properties.toMap() | |
} | |
private fun Project.readProperties(file: File): Properties { | |
return Properties().apply { | |
load(FileInputStream(file)) | |
} | |
} | |
// use it via gradle.kts | |
val envProps = getLocalOrDefaultProperties() | |
val properties01: String by envProps | |
val properties02: String by envProps |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment