【问题标题】:Maven dependency not in pom.xmlMaven 依赖项不在 pom.xml 中
【发布时间】:2014-02-19 18:19:02
【问题描述】:

我有一个使用弹簧的项目。它使用 3.1.1 版本,但出于某种我真的不知道的原因,一些 spring 工件与两个不同的版本重复。我在我的项目的所有 pom.xml 文件中查找这些依赖项。我还使用依赖插件来找出这些依赖项包含在哪里。

这里有mvn dependency:tree 的输出摘录

[INFO] |  |  \- org.springframework:spring-web:jar:3.1.1.RELEASE:compile
[INFO] |  |     +- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  |     +- org.springframework:spring-beans:jar:3.1.1.RELEASE:compile
[INFO] |  |     +- org.springframework:spring-context:jar:3.1.1.RELEASE:compile
[INFO] |  |     |  +- org.springframework:spring-aop:jar:3.1.1.RELEASE:compile
[INFO] |  |     |  +- org.springframework:spring-expression:jar:3.1.1.RELEASE:compile
[INFO] |  |     |  \- org.springframework:spring-asm:jar:3.0.5.RELEASE:compile
[INFO] |  |     \- org.springframework:spring-core:jar:3.0.5.RELEASE:compile

据我所知,这意味着org.springframework:spring-core:jar:3.0.5.RELEASE:compile 包含在org.springframework:spring-web:jar:3.1.1.RELEASE:compile 中。

我解决了这个问题,包括范围为 provided 的依赖项,但我需要知道为什么会发生这种情况。

更新: 似乎当我评论下一个代码时,jar 不包含在战争中。

<dependency>
    <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
    <version>${cxf-version}</version>
</dependency>
...
<properties>
    ...
    <cxf-version>2.4.2</cxf-version>
    <spring.version>3.1.1</spring.version>
</properties>

【问题讨论】:

  • 如果两个版本具有完全相同的依赖项和相同的工件和 groupId,我真的不敢相信这两个版本实际上都在类路径上。 Maven 应该管理它并且只包含一个。到目前为止,这一切看起来都是预期的行为,您正在尝试解决一个并非真正问题的问题。
  • 尝试mvn dependency:tree -Dverbose 以获取有关它是否实际包含的更多信息。

标签: java spring maven maven-2 maven-dependency-plugin


【解决方案1】:

spring-contextpom 定义了对spring-core 的依赖,其版本与spring-context 完全相同。

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>${project.version}</version>
    <scope>compile</scope>
</dependency>

因此,您的项目中必须有一个dependencyManagement,告诉maven 使用3.0.5.RELEASE 而不是3.1.1.RELEASE

看看你的 poms。 dependencyManagement 中一定有这样的内容。

<dependencyManagement>
    <dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring-core</artifactId>
        <version>3.0.5.RELEASE</version>
    </dependency>
</dependencyManagement>

根据您的 maven 版本,您也可以使用dependency import

PS:spring-asm 也一样

【讨论】:

  • 没有任何依赖管理
【解决方案2】:

如果我只将org.springframework:spring-web:jar:3.1.1.RELEASE 添加到项目中并通过mvn dependency:tree 显示树,则会出现以下输出:

[INFO] \- org.springframework:spring-web:jar:3.1.1.RELEASE:compile
[INFO]    +- aopalliance:aopalliance:jar:1.0:compile
[INFO]    +- org.springframework:spring-beans:jar:3.1.1.RELEASE:compile
[INFO]    +- org.springframework:spring-context:jar:3.1.1.RELEASE:compile
[INFO]    |  +- org.springframework:spring-aop:jar:3.1.1.RELEASE:compile
[INFO]    |  +- org.springframework:spring-expression:jar:3.1.1.RELEASE:compile
[INFO]    |  \- org.springframework:spring-asm:jar:3.1.1.RELEASE:compile
[INFO]    \- org.springframework:spring-core:jar:3.1.1.RELEASE:compile
[INFO]       \- commons-logging:commons-logging:jar:1.1.1:compile

从来没有提到过org.springframework:spring-core:jar:3.0.5.RELEASEorg.springframework:spring-asm:jar:3.0.5.RELEASE。这意味着您有其他依赖项引入了该依赖项,或者您正在使用依赖项管理块覆盖该依赖项。

【讨论】:

  • 谢谢,我正在寻找那个依赖,但我真的没有看到它。
猜你喜欢
  • 1970-01-01
  • 2021-11-23
  • 2021-11-16
  • 2022-01-20
  • 1970-01-01
  • 2013-11-06
  • 1970-01-01
  • 1970-01-01
  • 2013-03-09
相关资源
最近更新 更多