Created
December 12, 2013 05:23
-
-
Save lifuzu/7923568 to your computer and use it in GitHub Desktop.
Parse XML file in gradle
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
//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