MozenRath
MozenRath

Reputation: 10050

How to remove duplicate dependencies from pom?

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?

Upvotes: 5

Views: 11599

Answers (4)

shubham
shubham

Reputation: 482

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>

Upvotes: 6

viclisa
viclisa

Reputation: 41

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

Upvotes: 2

Jorge Viana
Jorge Viana

Reputation: 426

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.

Upvotes: 0

userJ
userJ

Reputation: 201

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.

Upvotes: 3

Related Questions