Reputation: 145
I'm new to Gradle and I don't know much about it, but in my gradle file I defined the following task:
task helloWorld {
description "Custom task"
ext.srcFile = file("build/reports/checkstyle/main.xml")
inputs.file srcFile
doLast{
println "Hello World!"
println project.version
def errorCheckStyle = new XmlParser().parse(srcFile)
errorCheckStyle.row.each { row ->
println row
}
throw new GradleException("Oops, there seems to be an error in the following file:\n" +
ext.srcFile)
}
}
I only have this as a base and I would like to know how I can go through this file and catch the first error, after that the exception appears.
Upvotes: 1
Views: 639
Reputation: 3387
task helloWorld {
description "Custom task"
ext.srcFile = file("build/reports/checkstyle/main.xml")
inputs.file srcFile
doLast{
println "Hello World!"
println project.version
try {
def errorCheckStyle = new XmlParser().parse(srcFile)
errorCheckStyle.row.each { row ->
println row
}
} catch (Exception ex) {
throw new GradleException("Oops, there seems to be an error in the following file:\n" + ext.srcFile)
}
}
}
Upvotes: 1