Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Duplicate Dependencies in Maven Pom

I would like to remove duplicate dependencies in maven pom.xml.

I would like answers to multiple tools Linux, Notepad++, Netbeans, Intellij ...even...VIM,etc.

example (I can obvious delete but I would like a search replace answer)

  `<dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-server</artifactId>
        <version>2.7</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet-core</artifactId>
        <version>2.7</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-jetty-http</artifactId>
        <version>2.7</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-moxy</artifactId>
        <version>2.7</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-jetty-http</artifactId>
        <version>2.7</version>
    </dependency>`  

Please write the answer locally links can be frustrating if removed. Thanks.

like image 717
Sein3i8 Avatar asked Jul 25 '17 15:07

Sein3i8


3 Answers

dependency:analyze-duplicate Analyzes the and tags in the pom.xml and determines the duplicate declared dependencies.

mvn dependency:analyze-duplicate
like image 65
Zaroual Mohamed Avatar answered Oct 15 '22 09:10

Zaroual Mohamed


you can use mvn dependency:tree command to find duplicate dependencies into your project.

Use the <exclusions> tag into <dependency> tag of the pom to exclude that duplicate dependencies from maven project.

<dependencies>
    <dependency>
      <groupId>test.ProjectX</groupId>
      <artifactId>ProjectX</artifactId>
      <version>2.0</version>
      <scope>compile</scope>
      <exclusions>
        <exclusion>  
          <groupId>test.ProjectY</groupId>
          <artifactId>ProjectY</artifactId>
        </exclusion>
      </exclusions> 
    </dependency>
  </dependencies>
like image 29
Mayank Sharma Avatar answered Oct 15 '22 09:10

Mayank Sharma


Run mvn clean It will tell you your duplicate dependencies. Then delete them.

like image 43
user1198289 Avatar answered Oct 15 '22 09:10

user1198289