Maven + Anthill + JUnit Reports

Can’t sleep…  It’s 3:30AM EST and I can’t sleep!  So, I figured I’d write about my recent battles with Maven, Anthill, and Junits.

I’ve recently converted a project from an Ant build over to a Maven build.  The motivation for doing this was that the project structure was starting to get a little messy and the development teams could benefit from having a well defined project structure for future development efforts not to mention dependency management.  While making the conversion, I decided to turn on junit reporting as this is standard practice in any healthy development project.  Since our build environment is backed by Anthill, I needed to emit junit report xml files so that Anthill could dutifully package junit reports for distribution to a mailing list.  I also wanted to have Anthill fail the build if a junit failed or errored out .  Sounds simple right?

Unfortunately, I encountered a few hurdles in getting Maven to play nicely with junits and getting Anthill to play nicely with the Maven way of doing things.  The problem was that:

  1. My project is a multi-module structure.  Each time unit tests are run, the junit report xml is dumped into the respective module’s target directory.  Anthill wants report xml aggregated up to a chosen directory.
  2. I want my build to fail if a junit error/failure is detected but continue to run.
  3. I don’t want to use site:site since this takes forever and generates  artifacts I don’t care about.

In order to achieve my goal, I needed to fall back to Ant tasks.  The Ant tasks that follow simply concatenates the generated junit test results into one file.  After concatenation, I load the file into a Ant properties so that I can search for key indicators of failure or errors.  If these are present, I flag the build as a fail and let this bubble up to Anthill to fail the build.

Anyway… This isn’t the most elegant solution, but it works.  Hope this helps someone.