【发布时间】:2016-07-07 22:13:47
【问题描述】:
我在一个 web 项目中使用了多个基于 spring 的 maven 存储库,但子 POM 使用的依赖项存在问题。
我有一个这样的父 POM:
<dependencyManagement>
<dependencies>
<!-- SPRING -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>4.3.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- SPRING SECURITY -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-bom</artifactId>
<version>4.1.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- SPRING BOOT -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.3.5.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- SPRING WS -->
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>2.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-security</artifactId>
<version>2.2.3.RELEASE</version>
</dependency>
<!-- OTHER DEPENDENCIES OMITTED -->
</dependencies>
</dependencyManagement>
还有一个像这样的子 POM:
<dependencies>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-security</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<!-- OTHER DEPENDENCIES OMITTED -->
</dependencies>
就我对 maven 排除的理解而言,这应该避免覆盖父 POM 版本,但由于 spring-ws-security 依赖于较低版本的 spring-core (4.0.9),其方法已更改 由于 NoSuchMethodError 异常,我无法在 tomcat 本地服务器上部署应用程序,该异常也可以在实际部署应用程序时触发,但对旧 spring-core 版本的依赖仍然存在。
如何避免这种依赖关系的覆盖? 或者是否有某种方式可以同时使用这两种依赖项(据我搜索,这并不安全)?
已经访问过的链接:
Similar problem, but from child to parent,
只是提到了一些,我也访问过其他人,但忘记了链接。
编辑:spring-ws 依赖项使用 spring 4.0.9,它覆盖了我在父 POM 中定义的 4.3.0 版本(我需要使用的版本)。
+- org.springframework.ws:spring-ws-core:jar:2.2.3.RELEASE:compile
[INFO] | | | +- org.springframework:spring-oxm:jar:4.3.0.RELEASE:compile (version managed from 4.0.9.RELEASE)
[INFO] | | | +- org.springframework:spring-web:jar:4.3.0.RELEASE:compile (version managed from 4.0.9.RELEASE)
[INFO] | | | \- org.springframework:spring-webmvc:jar:4.3.0.RELEASE:compile (version managed from 4.0.9.RELEASE)
【问题讨论】:
-
请列出您正在获取哪些版本的库以及您想要获取哪些版本。您可以运行
mvn dependency:tree来列出依赖项。 -
我列出了一些错误的依赖项@AntonKoscejev
-
因此,根据您对 Sundaraj 的回答的评论,我不确定您到底想达到什么目标。您希望那些 spring-* 工件是 4.3 版还是 4.0 版?由于您的父母,您获得了 4.3,但您说您不希望子项目改变这一点,所以您想获得 4.3?但是 spring-ws 2.2 与 spring 4.3 二进制不兼容,需要旧版本。因此,您要么需要在子级中使用 4.0(在父级中定义或在子级中覆盖),要么需要一些与 spring 4.3 二进制兼容的 spring-ws 版本。您究竟需要什么帮助?
-
对不起@AntonKoscejev的误解,我想使用4.3,因为其他依赖项使用该版本,除了不兼容并且需要旧版本的spring-ws,我想要的是spring-ws 与我的其他依赖项共存,这就是我试图排除的原因,否则 4.3 在不使用 BOM 时会被 4.0 覆盖,在使用它时(在这种情况下)4.3 版本是强制性的,并且 spring -ws 找不到一些旧版本的方法。
-
你不能在类路径上有两个不同版本的相同依赖项。好吧,你可以,但只能使用在正常情况下不想使用的非常复杂的技术。那么您是否希望带有 spring-ws 的项目使用 spring 4.0(例如,最终与 spring 4.0 库一起分发),而其他项目使用 spring 4.3(与 spring 4.3 一起分发)?如果是这种情况,您可以在使用 spring-ws 的项目中定义依赖管理部分,并使用它来覆盖您想要从父级获得的任何内容,包括覆盖 spring bom 版本。
标签: java spring maven-3 dependency-management netbeans-8