File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Ant, Maven and Other Build Tools and the fly likes maven2: explicitly inlcuding transitive dependencies Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "maven2: explicitly inlcuding transitive dependencies" Watch "maven2: explicitly inlcuding transitive dependencies" New topic
Author

maven2: explicitly inlcuding transitive dependencies

manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308
Hi,

i am going into maven2 and already see it is the right way to go

but one thing i am unsure at:
how do i avoid to get transitive dependencies implictly included? for instance:

project A depends on: x.jar
project B depends on: A, x.jar

for that combination my pom.xml of B includes A as a dependency. because of that x.jar gets transitively included too.

but in my sense of dependencies i think it is better to get a grasp of dependencies in a project if i have to include x.jar to B explicitly and not implictly through A.

is it possible to tell maven to handle dependencies like that or does this break maven's view of the repository?

thanks for your answer.


aldana software engineering blog & .more
manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308
hi folks,

i already found out how to do it. you need to provide a exclusions list. following pom.xml snippet:


but still i am very unhappy with it for my pom.xml get really messy! does anybody know a way how to enable exclusions for all transitive dependencies by default?
manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308
seems that i am talking to myself ...

i had a look a maven community. it seems that my issue is being a feature request
Ryan Kade
Ranch Hand

Joined: Aug 16, 2005
Posts: 69
Hi manuel,

No, I've been reading, but haven't had time to respond. Exclusions are one way to do it, although I don't think you have the syntax right. You have to specify the <exclusion> inside the <dependency>. At least, that's what the online docs say--it's possible a top-level <exclusion> tag exists and they just haven't updated the docs.

Another (and apparently better) way to do it is by specifying the transitive dependency as optional. In your example, the POM for Project A should include:



Then when project B adds Project A as a dependency, it won't also grab "x.jar".

You also may be able to use the "provided" scope to accomplish this, depending on what you're doing.

More information is here:

Optional Dependencies and Dependency Exclusions
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

seems that i am talking to myself ...

No no Reading and learning.


[My Blog]
All roads lead to JavaRanch
manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308
Exclusions are one way to do it, although I don't think you have the syntax right.

yes, you're right. was a quick snippet code copy/paste error.


Another (and apparently better) way to do it is by specifying the transitive dependency as optional.

ahh, i see. so the optional flag seems the opposite of the exclusions tag. i tell the dependency itself not to open up its dependencies to the outside world. with the exclusion tag it is the other way round, the instance which includes a dependency restricts the transitive inclusion.

never the less if maven's future request excludesAll tag gets implemented it is also quite handy, because i only have to place the exclude to the one inlcuded dependent-project. with the optional flag i would need to set the optional flag to all included dependencies.

but until this feature gets implemented in maven 2.1 i obviously will use the optional flag. well, let's see maybe i can help the development crew to develop this feature...
[ June 28, 2007: Message edited by: manuel aldana ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: maven2: explicitly inlcuding transitive dependencies
 
Similar Threads
Maven Repo Location
a query from Distilled
Including Local Jar Files
How do I create ".pom" files? (not pom.xml files)
Upgrading to a new version of Hibernate under Eclipse