Why Spring 3 needs explicit cglib dependency declaration when using Maven? Why Spring 3 needs explicit cglib dependency declaration when using Maven? spring spring

Why Spring 3 needs explicit cglib dependency declaration when using Maven?


It's because cglib is marked as an optional dependency.

Essentially you don't need cglib for every usage of the spring-aop library, so maven doesn't download it automatically. You need to specify it manually, unfortunately.


I'm a little confused... Maven is a dependency manager... Why it does not download the cglib when I use the spring-aop module ?

Because not everybody uses CGLIB (an AOP proxy in Spring can be a JDK dynamic proxy or a CGLIB proxy) so CGLIB is marked as an optional dependency in the pom of spring-aop and you have to add it explicitly if you want to use it. This is exactly what optional dependencies are for.

Another similar example is Hibernate that lets you choose between cglib and javassist in hibernate-core in the same way. Hibernate also lets you choose between various connection pools (if you decide to use one of them) or cache providers (only ehcache, the default, is not declared as optional).


My guess would be that cglib is not enabled in Spring by default. And therefore it's not included in the pom unless you explicitly enable it.

As far as I know, Maven cannot go into your Spring configuration files and determine if it needs additional optionally enabled libraries. Although, that certainly sounds like it would be a cool Spring-Maven plugin if it were possible to modify the pom on the fly via plugin. Not sure if it is, but it would be cool.