Posted by: bgopi | November 7, 2014

Reading properties from xml file using gradle

Here is how to read properties defined in xml file and store them in ext scope so that you can access in your gradle build script later.

file: build.gradle

task parseXml() {
def parsedPropXml = (new XmlParser()).parse(‘properties.xml’){ prop ->
project.ext.set(prop.@name, prop.@value)
println “<<print props>>” {k, v ->
println “$k: $v”
//retrieve individual property from ext
def propValue =“property_name”)
println “property_name: $propValue ”


prompt> gradle parseXml


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


%d bloggers like this: