2017-01-23 84 views
1

我有一個maven中的多模塊項目,其中一些模塊依賴於其他模塊。現在,充當依賴關係的模塊具有一些依賴關係,這些依賴關係已經列在依賴模塊的pom中。如何從pom中刪除重複的依賴關係?

有沒有一種快速的方法來識別這種重複的依賴關係,並將它們從依賴模塊的pom中移除?

回答

3

項目的依賴關係樹可以展開以顯示依賴關係衝突。 使用命令

mvn dependency:tree

識別這種重複的依賴關係。

使用pom的<dependency>部分下的<exclusions>標記排除這種重複的依賴關係。

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

你能舉一個例子說明'mvn dependency:tree'命令在這種情況下是否有用嗎? – MozenRath

+1

當您使用-Dverbose = true運行此命令時,它顯示所有重複項和衝突。 – shubham

1

如果您正在使用Eclipse作爲IDE然後重複的,可以在相關的pom.xml的依賴層級看到。使用排除標籤可以省略它們。

0

有一個JBoss工具來幫助解決這些問題:http://tattletale.jboss.org/ 不幸的是,這些天似乎並沒有得到積極的發展。