Resolving ASM Dependency Conflicts
Yesterday I ran into a rather tricky dependency issue. My final demo for my JavaZone talk depends on both Jen and Hibernate which again depend on different versions of the ASM library. There are quite a few frameworks that rely on this library, so I reckon that this is a rather common problem, but googling for a solution didn’t get me very far so a short post on the subject is in order.
JEN requires version 2.1 of ASM, while Hibernate uses 1.5.3. There are some breaking changes between these, so we’ll need both APIs to build and run the project. Hibernate gets its dependency on ASM via its CGLIB dependency, so the first thing you’ll need to do is to exclude Hibernate’s CGLIB dependency from the POM.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.5.ga</version>
<exclusions>
<exclusion>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
</exclusion>
</exclusions>
</dependency>
Hibernate will throw a ClassDefNotFoundException its expected ASM version isn’t in the class path at runtime. Luckily there is a distribution of CGLIB called cglib-nodep which, as the name indicates, has no external dependencies. Hibernate will gladly use this jar instead of the one it depends on so we’ll add a new dependency to the POM.
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>2.1_3</version>
</dependency>
Volia, no more ASM dependency headaches.