On Thu, Mar 14, 2013 at 5:29 PM, Patrick Schlebusch < patrick.schlebu...@kisters.de> wrote:
> Lets assume we have the artifacts A, B and C. B depends on C with scope > provided. B contains a class that extends a class of C. If A wants to use > this class of B, it should only need to add a dependency for B (lets > assume compile scope here). However, since provided scopes are not > resolved transitively A cannot be compiled without also specifying a > dependency on C, an artifact it shouldn't have to know about. Because a class in A transitively depends on a class provided by C then it *has* to know about C. Class hierarchy is part of the API (which is one reason you should generally prefer composition over inheritance). If B depends on C with scope=provided, then it's saying to anyone using B "you have to provide C". A uses B (it depends on it), so it has to provide C. There are cases where this wouldn't be necessary (if B uses C but doesn't expose it in its API) but they should be seen as the exception rather than the rule. Now A can decide how it provides C; if it only wants to provide it a compile-time, then it'll have it in scope=provided too. Because Maven resolves dependencies for you doesn't mean you shouldn't care about what those transitive dependencies are. I see Maven as a tool that makes it *easier* to get the dependencies right (rather than download JARs manually), but they're still under your responsibility. Another way to approach the problem would be to have B depends on C with scope=compile, so A would have the dependency "for free" (transitively). And it would be in the hand of A to decide whether C will be provided or not. But that depends a lot on the packaging you're using. This approach works well for packaging=jar, and you'll leave it to the "leaves" (roots?) of your dependency tree (packaging=war for instance) to decide what is provided and what is not. I don't know packaging=bundle much but maybe it'd be better to use scope=compile and exclude the JAR from being bundled at the maven-bundle-plugin level. Note that I'm not saying Maven couldn't do better; it definitely could: using scope=provided for annotation processors just seems wrong (there should be a scope=compile-only), you might also want to compile against one version and test against another, etc. -- Thomas Broyer /tɔ.ma.bʁwa.je/ <http://xn--nna.ma.xn--bwa-xxb.je/>