特定版本的 Maven 排除

Shi*_*iri 2 maven

我有一个带有 maven 依赖项的项目,它引入了两个包,其中一个引入了一个子依赖项,该子依赖项与另一个版本较低的包相同。该dependency:tree如下所示:

Dependency convergence error for xerces:xercesImpl:2.10.0 paths to dependency are:
+-com.vaadin:vaadin-client-compiler:7.6.4
  +-net.sourceforge.nekohtml:nekohtml:1.9.19
     +-xerces:xercesImpl:2.10.0
and
+-com.vaadin:vaadin-client-compiler:7.6.4
  +-xerces:xercesImpl:2.11.0
Run Code Online (Sandbox Code Playgroud)

以上是 maven 执行器插件的输出,我在其中强制执行依赖版本收敛。

有没有一种方法可以指定要排除的版本而不完全排除整个子依赖项?

Mat*_*ich 6

将你的 pom.xml 中的 net.sourceforge.nekohtml 依赖声明为一级依赖,并直接为其添加排除项。

参考:Maven 可选和排除

<dependency>
   <groupId>net.sourceforge.nekohtml</groupId>
   <artifactId>nekohtml</artifactId>
   <version>1.9.19</version>
   <exclusions>
      <exclusion>
        <groupId>xerces</groupId>
        <artifactId>xercesImpl</artifactId>
      </exclusion>
    </exclusions>
</dependency>
Run Code Online (Sandbox Code Playgroud)