2017-07-25 316 views
0

我想刪除maven pom.xml中的重複依賴項。刪除Maven Pom中的重複依賴項

我想多個工具的答案Linux,Notepad ++,Netbeans,Intellij ...甚至VIM等。

例子(我能明顯的刪除,但我想搜索替換的答案)

`<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>` 

請寫答案如果當地輾轉聯繫可能會令人沮喪。謝謝。

+1

通用的最佳實踐解決方案顯然是避免首先添加重複的依賴關係。一旦你達到了足夠多的'pom.xml'的重複依賴關係,你不能手動處理它們,我真的不確定開發一個自定義解決方案來移除它們的成本是值得的低成本離開他們和/或糾正他們,因爲你找到他們。 – Aaron

回答

1

運行 MVN清潔 它會告訴你你的重複的依賴關係。然後刪除它們。

+0

我仍然希望看到多行查找替換選項,但這是關於點。 – Sein3i8

+0

如何刪除它們? – NateH06

1

您可以使用mvn dependency:tree命令查找重複的依賴關係到您的項目中。

<exclusions>標記用於pom的<dependency>標記以從maven項目中排除重複的依賴項。

<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>