java - 将传递依赖行为与 xml-apis 混淆

标签 java maven dependency-management

在我的项目中,我依赖于多个外部库,这些库依赖于各种版本的 xml-apis .如果我使用 maven-enforcer-plugin to fail if there are version conflicts我的构建失败了。

在我开始之前,打印我正在运行的应用程序的类路径会得到 xml-apis:xml-apis:1.4.01

当我启用 maven-enforcer-plugin 时我明白了,这是意料之中的

Dependency convergence error for xml-apis:xml-apis:1.3.04 paths to dependency are:

+-org.bbraile:bbraile:1.0-SNAPSHOT
  +-org.bbraile:utd:1.0-SNAPSHOT
    +-xalan:xalan:2.7.2
      +-xalan:serializer:2.7.2
        +-xml-apis:xml-apis:1.3.04
and
+-org.bbraile:bbraile:1.0-SNAPSHOT
  +-org.bbraile:utd:1.0-SNAPSHOT
    +-xml-apis:xml-apis:1.4.01
and
+-org.bbraile:bbraile:1.0-SNAPSHOT
  +-org.bbraile:utd:1.0-SNAPSHOT
    +-xerces:xercesImpl:2.11.0
      +-xml-apis:xml-apis:1.4.01
and
+-org.bbraile:bbraile:1.0-SNAPSHOT
  +-com.io7m.xom:xom:1.2.10
    +-xml-apis:xml-apis:1.3.03
and
+-org.bbraile:bbraile:1.0-SNAPSHOT
  +-org.apache.xmlgraphics:batik-transcoder:1.7
    +-org.apache.xmlgraphics:batik-bridge:1.7
      +-org.apache.xmlgraphics:batik-anim:1.7
        +-xml-apis:xml-apis:1.3.04
and
+-org.bbraile:bbraile:1.0-SNAPSHOT
  +-org.apache.xmlgraphics:batik-transcoder:1.7
    +-org.apache.xmlgraphics:batik-bridge:1.7
      +-org.apache.xmlgraphics:batik-css:1.7
        +-xml-apis:xml-apis:1.3.04
and
+-org.bbraile:bbraile:1.0-SNAPSHOT
  +-org.apache.xmlgraphics:batik-transcoder:1.7
    +-org.apache.xmlgraphics:batik-bridge:1.7
      +-org.apache.xmlgraphics:batik-ext:1.7
        +-xml-apis:xml-apis:1.3.04
and
+-org.bbraile:bbraile:1.0-SNAPSHOT
  +-org.apache.xmlgraphics:batik-transcoder:1.7
    +-org.apache.xmlgraphics:batik-bridge:1.7
      +-xml-apis:xml-apis:1.3.04
and
+-org.bbraile:bbraile:1.0-SNAPSHOT
  +-org.apache.xmlgraphics:batik-transcoder:1.7
    +-org.apache.xmlgraphics:batik-dom:1.7
      +-xml-apis:xml-apis:1.3.04
and
+-org.bbraile:bbraile:1.0-SNAPSHOT
  +-org.apache.xmlgraphics:batik-transcoder:1.7
    +-org.apache.xmlgraphics:batik-gvt:1.7
      +-xml-apis:xml-apis:1.3.04
and
+-org.bbraile:bbraile:1.0-SNAPSHOT
  +-org.apache.xmlgraphics:batik-transcoder:1.7
    +-org.apache.xmlgraphics:batik-svg-dom:1.7
      +-xml-apis:xml-apis:1.3.04
and
+-org.bbraile:bbraile:1.0-SNAPSHOT
  +-org.apache.xmlgraphics:batik-transcoder:1.7
    +-org.apache.xmlgraphics:batik-svggen:1.7
      +-xml-apis:xml-apis:1.3.04
and
+-org.bbraile:bbraile:1.0-SNAPSHOT
  +-org.apache.xmlgraphics:batik-transcoder:1.7
    +-xml-apis:xml-apis:1.3.04

要根据我阅读的内容解决这个问题,我应该将其添加到我的 POM 中

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
            <version>2.0.2</version>
        </dependency>
    </dependencies>
</dependencyManagement>

然后重新运行我的程序。它通过 maven-enforcer-plugin检查但我的类路径说现在我正在运行 xml-apis:xml-apis:1.0.b2 .版本号怎么老了?为什么我的版本被忽略了?

将此添加到我的 POM,有或没有 <version>标签无效

<dependencies>
    <dependency>
        <groupId>xml-apis</groupId>
        <artifactId>xml-apis</artifactId>
        <version>2.0.2</version>
    </dependency>
</dependencies>

咨询dependency:tree -Dverbose=true -Dincludes=xml-apis下面给出,这意味着 2.0.2

org.bbraile:bbraile:jar:1.0-SNAPSHOT
+- org.bbraile:utd:jar:1.0-SNAPSHOT:compile
|  +- xalan:xalan:jar:2.7.2:compile
|  |  \- xalan:serializer:jar:2.7.2:compile
|  |     \- (xml-apis:xml-apis:jar:2.0.2:compile - version managed from 1.0.b2; omitted for duplicate)
|  +- (xml-apis:xml-apis:jar:2.0.2:compile - version managed from 1.0.b2; omitted for conflict with 1.0.b2)
|  \- xerces:xercesImpl:jar:2.11.0:compile
|     \- (xml-apis:xml-apis:jar:2.0.2:compile - version managed from 1.0.b2; omitted for duplicate)
+- com.io7m.xom:xom:jar:1.2.10:compile
|  \- (xml-apis:xml-apis:jar:2.0.2:compile - version managed from 1.0.b2; omitted for duplicate)
+- org.apache.xmlgraphics:batik-transcoder:jar:1.7:compile
|  +- org.apache.xmlgraphics:batik-bridge:jar:1.7:compile
|  |  +- org.apache.xmlgraphics:batik-anim:jar:1.7:compile
|  |  |  +- (xml-apis:xml-apis:jar:2.0.2:compile - version managed from 1.0.b2; omitted for duplicate)
|  |  |  \- (xml-apis:xml-apis-ext:jar:1.3.04:compile - omitted for duplicate)
|  |  +- org.apache.xmlgraphics:batik-css:jar:1.7:compile
|  |  |  +- (xml-apis:xml-apis:jar:2.0.2:compile - version managed from 1.0.b2; omitted for duplicate)
|  |  |  \- (xml-apis:xml-apis-ext:jar:1.3.04:compile - omitted for duplicate)
|  |  +- org.apache.xmlgraphics:batik-ext:jar:1.7:compile
|  |  |  \- (xml-apis:xml-apis:jar:2.0.2:compile - version managed from 1.0.b2; omitted for duplicate)
|  |  +- (xml-apis:xml-apis:jar:2.0.2:compile - version managed from 1.0.b2; omitted for duplicate)
|  |  \- (xml-apis:xml-apis-ext:jar:1.3.04:compile - omitted for duplicate)
|  +- org.apache.xmlgraphics:batik-dom:jar:1.7:compile
|  |  +- (xml-apis:xml-apis:jar:2.0.2:compile - version managed from 1.0.b2; omitted for duplicate)
|  |  \- (xml-apis:xml-apis-ext:jar:1.3.04:compile - omitted for duplicate)
|  +- org.apache.xmlgraphics:batik-gvt:jar:1.7:compile
|  |  \- (xml-apis:xml-apis:jar:2.0.2:compile - version managed from 1.0.b2; omitted for duplicate)
|  +- org.apache.xmlgraphics:batik-svg-dom:jar:1.7:compile
|  |  +- (xml-apis:xml-apis:jar:2.0.2:compile - version managed from 1.0.b2; omitted for duplicate)
|  |  \- (xml-apis:xml-apis-ext:jar:1.3.04:compile - omitted for duplicate)
|  +- org.apache.xmlgraphics:batik-svggen:jar:1.7:compile
|  |  \- (xml-apis:xml-apis:jar:2.0.2:compile - version managed from 1.0.b2; omitted for duplicate)
|  +- (xml-apis:xml-apis:jar:2.0.2:compile - version managed from 1.0.b2; omitted for duplicate)
|  \- xml-apis:xml-apis-ext:jar:1.3.04:compile
\- xml-apis:xml-apis:jar:2.0.2:compile

为什么我在 dependencyManagment 中的显式版本被忽略了?为什么设置会降低我的类路径上的版本?我怎样才能通过 maven-enforcer-plugin与最近的 xml-apis版本?

最佳答案

原来这不是maven的问题,这是xml-api的问题。截至今天,这就是 xml-apis:xml-apis 在 Maven Central 中的样子

Very confusing xml-apis versions

如果您仔细观察,2.0.2 不是最新版本,1.4.01 才是!当其他人和他们的 IDE 认为 2 大于 1 时,xml-apis 倒退了。

这是非常令人困惑和不明显的,所以希望有人觉得这很有用。

关于java - 将传递依赖行为与 xml-apis 混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29354632/

相关文章:

java - 有没有 Eclipse API 可以解析 CSS 和 HTML?

java - 解决org.apache.hadoop.conf.Configuration时出错

java - Maven - 在安装时重命名第三方 jar

maven - 使用 maven 在 kotlin 中编写 JSP - 实例化 servlet 类时出错,ClassNotFoundException

go - 如何从 Go 模块导入特定的包?

maven - 使用 maven 作为 MPS baseLanguage 模型的依赖管理器?

java - 我的 java spring boot 代码有什么问题

Java 和 XSS : How to html escape a JSON string to protect against XSS?

java - 如何检查 Maven 依赖兼容性

java - 使用 hadoop 进行数据分析