Parsing and checking JUnit XML Report with Gradle

I have an exec task that executes some javascript tests and outputs an JUnit XML report files. I would like to use Gradle to check these reports for failures and fail the build with an informative message, is there a good way of doing this?

You’ll have to write a task that parses the XML and throws an exception if it finds a failure. Parsing XML is easy with Groovy’s ‘XmlSlurper’ (search the web for more information).