Maven 2 and Junit 4


I have been revisiting the tools I use in my preferred Java web application development stack. Some of these are being used by me for the first time (Velocity, Eclipse Web Tools Project) or replace older tools that served similar roles (Subversion, Maven, Spring Framework). Others are newer versions that introduce invaluable feature sets (Java 5, Junit 4). All of the tools are open source software and freely available thanks to the Herculean efforts of the community and the generous donations of coporations.

I intend to write more about how I evaluate tools in my preferred Java web development stack, but the general principle is that a) each component must be mature enough and have a strong enough community to sustain future growth, b) each component should be largely orthogonal to the others, c) each component should have a "backup plan" in case things don't work out, and d) no component should lock the developer in to any other component or set of dependencies.

One of the great things about open source tools is that people tend to find clever ways to make them work together. Nearly all of the best modern open source development tools, from IDEs to build and deployment systems, support plugin architectures to extend their core functionality. Whereas a closed source commercial tool vendor might try and retain tight control over what their tool interoperates with (sometimes forcing you deep into a dependency chain with their own products), open source projects tend to recognize that success and a high adoption rate is entirely dependent on broad and agnostic interoperability.

Unfortunately this means that those on the bleeding edge are often out ahead of curve regarding the plugins and glue code that connects the latest and greatest components. This bit me last year as I attempt to use Maven 2 with the Eclipse Web Tools Project. No fault of either community; they simply had not finished the work required to make the projects work together.

Similarly, the new version of JUnit, which introduces a remarkable elegance and convenience in unit testing, does not yet play nicely with Maven 2, the rewrite of the powerful and intuitive goal-driven build system. Older versions of the two tools interoperated thanks to the wonderful Surefire plugin. However JUnit 4 is so new that work hasn't been completed yet on supporting JUnit 4 tests in Surefire. Completely understandable and it pays to be patient.

Of course, when it comes to unit testing one shouldn't be patient. Or at least, one shouldn't find an excuse to put off writing the unit tests.

So I decided to learn a little bit about Maven plugin development and wrote a very basic plugin that runs JUnit 4 tests. It is not intended to replace Surefire. In fact, the minute that Surefire supports JUnit 4 I will take down the page for this plugin. But if you need something to get the job done today, in spite of all its numerous limitations, feel free to grab the temporary plugin that I wrote.

The temporary Maven JUnit4 plugin.


I will be out of town for a couple of days. When I come back I will try and fully document the Java web application development stack that I am using.

In the meantime I would love to hear what tools other people find indispensable when building Java web applications. One thing I am particularly interested in is tools that increase personal development efficiency. I haven't had the time to program on the job for many months, so tools that help get work done in the stolen moments of the early morning and late night are very much appreciated.