views:

1281

answers:

3

Hello,

I'm using spring 3 and maven. I've defined all spring modules in my pom.xml.

When I use <aop:scoped-proxy /> annotation, I've got an error saying that cglib is missing.

Well... I add cglib dependency in my pom and all runs...

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

It's not the only case... Why some projects need explicit dependency declaration instead of using maven transitive dependency mechanism ?

+1  A: 

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.

Mike Cornell
+8  A: 

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.

Phill Sacre
+1 for your answer
c0mrade
exact, I just discover the optional feature ;)But when a dependency is declared as optional, it's just for doc ? or there is a way to activate it in the module declaration ?
Jerome C.
@Jerome as I understand it the dependency is downloaded when they build spring-aop, but not when you build a project which depends on spring-aop. If that makes sense!
Phill Sacre
+4  A: 

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).

Pascal Thivent