如何覆盖maven中artifact包含的库的默认版本?
我在pom.xml中有一个弹簧批量的依赖性,如下所示:
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-core</artifactId>
<version>3.0.9.RELEASE</version>
</dependency>
有一个Artifact Xstream,上述版本为1.4.7,需要更新为1.4.11。
可以添加如下:
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.11</version>
</dependency>
正确的方法是什么?我正在考虑以下方法:
上面的代码将在那里,但我需要使用&lt;排除&gt;要专门从弹簧批次核心中排除Xstream trifact旧版本,还是Maven会自动照顾此版本?
I have a spring batch dependency in my pom.xml declared as below:
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-core</artifactId>
<version>3.0.9.RELEASE</version>
</dependency>
There is one artifact xstream that is included by above with version 1.4.7 and it needs to be updated to 1.4.11.
It can be added as follow:
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.11</version>
</dependency>
What is the correct way for this?I am thinking of following approach:
Both above pieces of code will be there but do I need to use < exclusions > to specifically exclude xstream artifact old version from spring-batch-core or does maven takes care of this automatically?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更好的方法是使用
标签。依赖管理将确保即使其他一些传递依赖带来更高版本的依赖,版本也会得到维护。用法:
注意:
dependencyManagement
标签用于定义依赖项的版本和范围(如果不在编译的默认范围内),它不会将其中的依赖项添加到您的项目中,您必须定义pom.xml 中单独的
部分,用于向项目添加依赖项。在你的情况下,它会像。
在这种情况下,
spring-batch-core
被添加为直接依赖项,如果它有xstream
作为依赖项,您的项目将使用1.4.11
版本甚至 spring-batch-core 也有不同版本的 xstream 作为依赖项。参考: 依赖管理
Better way will be using
<dependencyManagement/>
tag. Dependency management will make sure the version will be maintained even if some other transitive dependency brings higher version of the dependency.Usage:
Note:
dependencyManagement
tag is used for defining the version and scope (if not in the default scope which is compile) of a dependency it does not add the dependencies in it to you project, you must define separate<dependencies/>
section in your pom.xml for adding dependencies to your project.In your case it will be like.
In this case
spring-batch-core
is added as a direct dependency and if it hasxstream
as dependecny you project will use1.4.11
version evenspring-batch-core
has a different version ofxstream
as dependency.Ref: Dependency Management