Created
October 31, 2012 06:03
-
-
Save xconnecting/3985220 to your computer and use it in GitHub Desktop.
Gradle: Change setting using P option
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
defaultTasks 'dbsetting' | |
def envList = ['dev', 'qa', 'prod'] | |
if (!hasProperty('env')) { | |
ext.env = System.env['GRADLE_ENV'] ?: envList[0] | |
} | |
if(!envList.find{it == ext.env}){ | |
throw new Exception("There is no environment named '$ext.env'") | |
} | |
ext.setting = { | |
def slurper = new ConfigSlurper() | |
def files = files("env/default.gradle", | |
"env/${env}.gradle", | |
"${System.properties['user.home']}/.gradle/${env}.gradle") | |
files.inject(new ConfigObject()) { config, file -> | |
file.exists() ? config.merge(slurper.parse(file.toURL())) : config | |
} | |
}() | |
task dbsetting << { | |
println "dbname: $setting.database.dbname" | |
println "user: $setting.database.username" | |
println "password: $setting.database.password" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment