[英]Override dependencies of third party jar in maven
像這個org.carrot2
取決於commons-httpclient 3.1
那么我如何將這個commons-httpclient 3.1
更改為HttpClient 4.1.1
。 我在 eclipse 工作。 因為我想從依賴此 jar 文件的人中刪除commons-httpclient:3.1
並且我想用HttpClient 4.1.1
替換。
所以我想要做什么..我從依賴層次結構文件夾中雙擊這個org.carrot2
並進入它的 pom.xml 文件並試圖將commons-httpclient 3.1
更改為 httpclient 4.1.1 但它不允許我更改為退格並刪除不起作用..
任何建議將不勝感激..
首先請確保上述工件可以與 HttpClient 4.1.1 正常工作。
我們可以為每個依賴項定義“排除”,因為它在http://maven.apache.org/pom.html#Exclusions中提到
排除明確告訴 Maven 您不想包含作為此依賴項的依賴項的指定項目(換句話說,它的傳遞依賴項)
excludes :Exclusions 包含一個或多個排除元素,每個包含一個 groupId 和 artifactId 表示要排除的依賴項。 與可能會或可能不會安裝和使用的可選項不同,排除項會主動將自己從依賴關系樹中刪除。
<dependencies>
<dependency>
<groupId>the_group</groupId>
<artifactId>the_artifact</artifactId>
<version>the_version</version>
<exclusions>
<exclusion>
<groupId>the_apache_group</groupId>
<artifactId>the_http_client_artifact</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>the_apache_group</groupId>
<artifactId>the_http_client_artifact</artifactId>
<version>4.1.1</version>
</dependency>
...
</dependencies>
我希望這可能有助於實現要求。
問候,
查理·Ch。
將 HttpClient 4.1.1 的依賴項添加到您的POM。 Maven 將識別您的直接依賴和間接依賴之間的沖突(假設 httpclient 的 groupId 和 artifactId 未更改),並使用較新的版本。 (不是因為它較新,而是因為它更直接)
而且你不能編輯其他人的 pom 文件是有道理的——畢竟,你希望胡蘿卜只在你的程序中使用更新的 http 客戶端,而不是在所有使用胡蘿卜的程序中......
如果某些東西依賴於HttpClient
3.x
,它將無法替代4.x
,因為它們是完全不同的 API。 嘗試訪問依賴於3.x
的代碼時,您會遇到運行時錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.