4

I have a multi-module project in maven where some of the modules depend on other modules. Now the modules that act as dependencies have some of the dependencies which are already listed in the dependent module's pom.

Is there a quick way to identify such duplicate dependencies and remove them from the dependent module's pom?

MozenRath
  • 9,652
  • 13
  • 61
  • 104

4 Answers4

6

A project's dependency tree can be expanded to display dependency conflicts. Use command

mvn dependency:tree -Dverbose=true

to identify such duplicate dependencies. It shows all duplicates and conflicts in the pom.

Use the <exclusions> tag under the <dependency> section of the pom to exclude such duplicate dependencies.

<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>
MozenRath
  • 9,652
  • 13
  • 61
  • 104
shubham
  • 472
  • 3
  • 9
3

If you are using eclipse as IDE then the duplicates can be seen in the dependency hierarchy of the concerned pom.xml. And using exclusions tag they can be ommitted.

userJ
  • 181
  • 1
  • 4
2

You can use mvn depgraph:graph -Dincludes=ets.tkt -DshowDuplicates -Dscope:compile. To use this plugin put this on your settings.xml

<settings>
  . . .
  <pluginGroups>
    <pluginGroup>com.github.ferstl</pluginGroup>
  </pluginGroups>

</settings>

When you run the previous console command, you can go to /target and you will find a .dot file. you can render this file using graphviz. More info at https://github.com/ferstl/depgraph-maven-plugin

viclisa
  • 41
  • 4
0

There is a JBoss tool to help with these issues: http://tattletale.jboss.org/ Unfortunately, it seems that is not under active development these days.

Jorge Viana
  • 396
  • 5
  • 12