• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

maven2: explicitly inlcuding transitive dependencies

 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
manuel aldana
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
seems that i am talking to myself ...

i had a look a maven community. it seems that my issue is being a feature request
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

seems that i am talking to myself ...


No no Reading and learning.
 
manuel aldana
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic