如何更新或替换Maven项目中其他库的依赖项?

问题描述 投票:0回答:1

我的项目正在使用另一个我无法控制的库公共集合。我运行命令:

mvn dependency:tree -Dverbose -Dincludes=commons-collections

Verbose not supported since maven-dependency-plugin 3.0
[INFO] com.jde.jnlu:jnlu-qe-web:war:1.0.0-SNAPSHOT
[INFO] \- com.jde.jimi3.data:jd-jimi3-data-sdk:jar:3.0-SNAPSHOT:compile
[INFO]    \- com.jde.jmq:jmq-client-spring:jar:2.1.2:compile
[INFO]       \- com.jde.jmq:jmq-client-core:jar:2.1.2:compile
[INFO]          \- com.jde.jmq:jmq-client-json:jar:1.2.9:compile
[INFO]             \- commons-beanutils:commons-beanutils:jar:1.9.2:compile
[INFO]                \- commons-collections:commons- 
             collections:jar:3.2.1:compile

可以看出,“commons-collections”是由jd-jimi3-data-sdk引入的,我无法更新。但我被提醒当前版本的“commons-collection”存在潜在的安全问题,需要进行升级。我怎样才能在我的项目中实现这一目标?

maven
1个回答
-1
投票

在您的项目中,如果您声明对所需的commons-collection版本的显式依赖,Maven将使用它。请参阅Maven文档:Resolving conflicts using the dependency tree

如果你想确定,你也可以(除了上面的内容)从你的jd-jimi3-data-sdk依赖项中排除commons-collection。就像是:

<project>
  ...
  <dependencies>
    <dependency>
      <groupId>com.jde.jimi3.data</groupId>
      <artifactId>jd-jimi3-data-sdk</artifactId>
      <version>3.0-SNAPSHOT</version>
      <scope>compile</scope>
      <exclusions>
        <exclusion>
          <groupId>commons-collections</groupId>
          <artifactId>commons-collections</artifactId>
        </exclusion>
      </exclusions> 
    </dependency>
  </dependencies>
</project>

这也包含在Maven文档中:Dependency Exclusions

警告:由于您使用的库 - jd-jimi3-data-sdk - 不是使用此版本的commons-collections编写的,并且据称未使用它进行测试,这可能会破坏您的项目!

© www.soinside.com 2019 - 2024. All rights reserved.