Maven Enforcer 插件识别 Camel-CXF 中的依赖收敛问题

Maven Enforcer plugin identifies Dependency Convergence issue within Camel-CXF

Maven enforcer 插件正在识别我正在使用的第 3 方库的代码收敛问题。我怎样才能忽略这个,同时仍然 运行 在项目的其余部分上使用项目上的 enforcer 插件,或者我应该如何在不更改库版本的情况下解决这个问题?

我的项目使用 camel-cxf 2.13.2,它依赖于 jaxb-impl 的两个独立的传递版本; 2.1.13 和 2.2.6。 enforcer 插件识别到这一点并导致构建失败。

这是我配置插件的方式:

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>1.3.1</version>
        <configuration>
            <rules>
                <DependencyConvergence/>
            </rules>
        </configuration>
    </plugin>

当我运行mvn enforcer:enforce我得到

Rule 0: org.apache.maven.plugins.enforcer.DependencyConvergence failed with message:
Failed while enforcing releasability the error(s) are [
Dependency convergence error for com.sun.xml.bind:jaxb-impl:2.2.6 paths to dependency are:
+-com.myModule:module:18.0.0-SNAPSHOT
  +-org.apache.camel:camel-cxf:2.13.2
    +-org.apache.camel:camel-core:2.13.2
      +-com.sun.xml.bind:jaxb-impl:2.2.6
and
+-com.myModule:module:18.0.0-SNAPSHOT
  +-org.apache.camel:camel-cxf:2.13.2
    +-org.apache.cxf:cxf-rt-bindings-soap:2.7.11
      +-org.apache.cxf:cxf-rt-databinding-jaxb:2.7.11
        +-com.sun.xml.bind:jaxb-impl:2.1.13
and
+-com.myModule:module:18.0.0-SNAPSHOT
  +-org.apache.cxf:cxf-rt-management:2.7.11
    +-org.apache.cxf:cxf-rt-core:2.7.11
      +-com.sun.xml.bind:jaxb-impl:2.1.13

我认为您不希望 Maven 在出现收敛错误时使构建阶段失败。 在这种情况下,您需要在配置中设置 fail = false 标志,这样它只会记录收敛错误并继续下一阶段。

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-enforcer-plugin</artifactId>
  <version>3.0.0-M1</version>
  <executions>
    <execution>
      <id>dependency-convergence</id>
      <phase>install</phase>
      <goals>
        <goal>enforce</goal>
      </goals>
      <configuration>
        <rules>
          <DependencyConvergence />
        </rules>
        <fail>false</fail>
      </configuration>
    </execution>
    <executions>
      <plugin>

注意:maven-enforcer-plugin 1.3.1版本很旧。考虑升级到最新的 3.x.x.

最后,我对特定的子依赖项添加了排除项,这些依赖项引入了旧的、冲突的 jaxb-impl 版本。

<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-core</artifactId>
    <version>${cxf.version}</version>
    <exclusions>
        <exclusion>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
        </exclusion>
    </exclusions>
    <scope>${framework.scope}</scope>
</dependency>
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-databinding-jaxb</artifactId>
    <version>${cxf.version}</version>
    <exclusions>
        <exclusion>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
        </exclusion>
    </exclusions>
</dependency>

这样我仍然可以 运行 项目其余部分的 enforcer 插件,如果发现新的收敛问题则构建失败。