Ever came across the need to use your Maven settings in your Grails application ?
This small snippet reads and parses your local .m2/settings.xml and copies all "properties" entry in your locale Grails context.
Config.groovy
// locations to search for config files that get merged into the main config
// config files can either be Java properties files or ConfigSlurper scripts
File mavenSettingsFile = new File(System.getProperty('user.home')+"/.m2/settings.xml")
if (mavenSettingsFile.exists()) {
def settingsXml = new XmlSlurper().parse(mavenSettingsFile)
settingsXml.profiles.profile.find{ it.id.equals(System.getProperty('maven.profile'))}."properties".children().each{ nodeChild ->
setProperty("${nodeChild.name()}", nodeChild.text())
println "Config: importing property from profile \"${System.getProperty('maven.profile')}\" : ${nodeChild.name()}=${nodeChild.text()}"
}
}else{
grails.config.locations = [
"classpath:application.properties"]
// "classpath:${appName}-config.groovy",
// "file:${userHome}/.grails/${appName}-config.properties"]
// "file:${userHome}/.grails/${appName}-config.groovy"]
}
All you have to do to use one of your local profile is exectute any grails goal with the given profile e.g. :
grails -Dmaven.profile=test run-app
Keine Kommentare:
Kommentar veröffentlichen