tags:

views:

113

answers:

2

Currently I am using Ivy for dependency management. And quite often I come across problem of getting identical jar files with different name due to transitive dependency.

Example:

<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>mail</artifactId>
    <version>1.4</version>
</dependency>

<dependency>
    <groupId>org.apache.geronimo.specs</groupId>
    <artifactId>geronimo-javamail_1.4_spec</artifactId>
    <version>1.4</version>
</dependency>

I am thinking of trying out Maven as well.

Any best practice to eliminate these identical artifact in either Ivy or Maven?

A: 

In this particular example i would select the the javax one. And if you have artifacts which are coming under different names you can use excludes in Maven. I don't know if this is possible in Ivy.

khmarbaise
Yes, it is possible in Ivy to exclude. But I would like to look for an alternative solution so that me and my colleague do not need to repeat these exclude in each project. Currently I am looking into setting up a Maven repository manager (using Nexus) and not sure will this help.
ThiamTeck
Define a dependencyManagement part in a parent pom, deploy it to your Nexus and any other colleague can use it.
khmarbaise
A: 

Global exclusion of artifacts would be a nice feature to deal with this kind of situation - same artifact with different names - until Maven provides a better way to deal with "Specs JARs" aka Virtual Dependencies.

Unfortunately, such a feature is currently not available (see MNG-3196 and MNG-1977) so you will have to declare dependency exclusions to exclude the unwanted artifact from the dependency pulling it transitively. In Maven, this is done by adding an <exclusions> tag under the <dependency> section of the pom.

<project>
  ...
  <dependencies>
    <dependency>
      <groupId>sample.ProjectA</groupId>
      <artifactId>Project-A</artifactId>
      <version>1.0</version>
      <scope>compile</scope>
      <exclusions>
        <exclusion>  <!-- declare the exclusion here -->
          <groupId>sample.ProjectB</groupId>
          <artifactId>Project-B</artifactId>
        </exclusion>
      </exclusions> 
    </dependency>
  </dependencies>
</project>

If Project-A-1.0.jar is used by all projects, one possible solution would be to declare this under the dependencyManagement section of a corporate POM to not repeat yourself.

Pascal Thivent
Thanks for your pointers, I found that Ivy actually support the [global exclusion](http://ant.apache.org/ivy/history/trunk/ivyfile/exclude.html).
ThiamTeck
@ThiamTeck Ahh, nice from Ivy (I'm more a Maven guy, wasn't aware of that). Thanks for the feedback.
Pascal Thivent