java Maven中相同依赖项的不同版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4827335/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Different versions of the same dependency in Maven
提问by biziclop
I have a maven project that depends on both Woodstox and XStream. Unfortunately XStream also depends on Woodstox, but a version slightly older than what I need. In the meantime though, the artifact names of the Woodstox libs changed, so maven won't consider them multiple versions of the same artifact. But the package and class names are the same, which means there is a conflict at runtime.
我有一个依赖 Woodstox 和 XStream 的 Maven 项目。不幸的是,XStream 也依赖于 Woodstox,但版本比我需要的略旧。与此同时,Woodstox 库的工件名称发生了变化,因此 maven 不会将它们视为同一工件的多个版本。但是包名和类名是一样的,这意味着在运行时存在冲突。
Now, I could obviously hack the old woodstox jar out of the build (a war
file in our case) somehow but what is the proper way of solving this type of problem?
现在,我显然可以war
以某种方式从构建中破解旧的 woodstox jar(在我们的例子中是一个文件),但是解决此类问题的正确方法是什么?
回答by Raghuram
You could try excluding
woodstox dependency in your dependency
declaration for xstream.
您可以excluding
在 xstream 的dependency
声明中尝试woodstox 依赖项。
<dependency>
<groupId>xstream.group</groupId>
<artifactId>xstream</artifactId>
<version>a.b.c</version>
<exclusions>
<exclusion>
<groupId>woodstox.group</groupId>
<artifactId>woodstox</artifactId>
</exclusion>
</exclusions>
</dependency>
回答by Sean Patrick Floyd
If you are lucky, the solution suggested by Raghuram will work.
如果幸运的话,Raghuram 建议的解决方案会奏效。
If not, you will have to create a modified version of the XStream jar, probably using the Maven Shade Plugin, merging both XStream woodstox into one Jar, renaming all woodstox packages.
如果没有,您将不得不创建 XStream jar 的修改版本,可能使用Maven Shade Plugin,将两个 XStream woodstox 合并到一个 Jar 中,重命名所有 woodstox 包。