java – 覆盖maven中第三方jar的依赖关系

像这样org.carrot2依赖于commons-httpclient 3.1所以我如何将这个commons-httpclient 3.1更改为HttpClient 4.1.1.我在日食工作.正如我想删除
commons-httpclient:3.1来自那些依赖于这个jar文件的人,我想用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所述

Exclusions explicitly tell Maven that
you don’t want to include the
specified project that is a dependency
of this dependency (in other words,
its transitive dependency)

exclusions: Exclusions contain one or
more exclusion elements, each
containing a groupId and artifactId
denoting a dependency to exclude.
Unlike optional, which may or may not
be installed and used, exclusions
actively remove themselves from the
dependency tree.

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

我希望这可能有助于实现这一要求.

问候,

Charlee Ch.

转载注明原文:java – 覆盖maven中第三方jar的依赖关系 - 代码日志