Skip to content

Instantly share code, notes, and snippets.

@lifuzu
Created December 12, 2013 05:23
Show Gist options
  • Save lifuzu/7923568 to your computer and use it in GitHub Desktop.
Save lifuzu/7923568 to your computer and use it in GitHub Desktop.
Parse XML file in gradle
//Declaring the inputs and outputs of a task
//build.gradle
task transform {
ext.srcFile = file('mountains.xml')
ext.destDir = new File(buildDir, 'generated')
inputs.file srcFile
outputs.dir destDir
doLast {
println "Transforming source file."
destDir.mkdirs()
def mountains = new XmlParser().parse(srcFile)
mountains.mountain.each { mountain ->
def name = mountain.name[0].text()
def height = mountain.height[0].text()
def destFile = new File(destDir, "${name}.txt")
destFile.text = "$name -> ${height}\n"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment