简体   繁体   English

Maven在WAR中捆绑了相同库的多个版本

[英]Maven bundles multiple versions of same libraries in WAR

I got NoSuchMethodError exceptions when running test from Maven build. 从Maven构建运行测试时,我得到了NoSuchMethodError异常。 I realized Maven bundles multiple versions of same libraries in war (some transitive dependencies has different versions). 我意识到Maven在战争中捆绑了相同库的多个版本(一些传递依赖有不同的版本)。 Is it default behaviour? 这是默认行为吗? I fail too see how could someone want it. 我也失败了,看到有人想要它。 Also, I found that exclusion tag can't have version (or range) so I can't exclude conflicting version. 另外,我发现排除标记不能有版本(或范围),所以我不能排除冲突版本。 Is there any way to prevent Maven from adding multiple versions of same library to war? 有没有办法阻止Maven将同一个库的多个版本添加到战争中? Thank you. 谢谢。

EDIT: Yeah, I can exclude it and depend on it in my POM. 编辑:是的,我可以将它排除在我的POM中并依赖它。 But it's far from elegant solution (can cause problems with changes in upstream). 但它远非优雅的解决方案(可能导致上游变化的问题)。

You can configure the assembly-plugin to exclude some dependencies. 您可以配置程序集插件以排除某些依赖项。 But that would be the same as excluding duplicates with different versions in the dependencies section. 但这与在依赖项部分中排除具有不同版本的重复项相同。 So I highly recommend to exclude the duplicates in the dependencies section. 所以我强烈建议在依赖项部分中排除重复项。 Also your project might lack a proper dependency management. 您的项目也可能缺乏适当的依赖关系管理。 If you use this correctly, you have all exclusions in the same pom. 如果您正确使用此功能,则会在同一个pom中包含所有排除项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM