Maven, JMock and Hibernate

I use JMock a lot. I use Hibernate a lot. And now I’m using Maven more and more. Those three things aren’t terribly fond of living together comfortably.

Here’s the problem. If you want to mock abstract classes in addition to interfaces, then JMock depends on CGLIB. Hibernate also depends on CGLIB. Unfortunately, the Maven POMs for those two packages introduce a situation where Maven can’t recognize that it’s being asked to use two very different releases of CGLIB. Hibernate depends on CGLIB 2.1 (which gets resolved to a cglib-2.1_3.jar), and JMock depends on version 2.0. Unfortunately, the artifact id for the former is “cglib” and the artifact id for the latter is “cglib-full”. Maven can’t recognize that those two artifacts overlap. And so I get two different versions of CGLIB on my classpath, and whenever I run Hibernate unit tests, I get a nasty Exception:

java.lang.NoSuchMethodError: net.sf.cglib.proxy.Enhancer.setInterceptDuringConstruction(Z)V

It’s a simple thing to resolve… just use an exclusion (like so):


I’ve used CGLIB, directly, on past projects, and I understand what it’s doing pretty well. So it was easy for me to figure out how to resolve the problem. But i can easily imagine a lot of people wasting a lot of time trying to figure out what’s happening.

It's only fair to share...
Share on FacebookGoogle+Tweet about this on TwitterShare on LinkedIn

Leave a Reply