Maven 2 - different dependency versions in test and compile

為{幸葍}努か 提交于 2019-12-05 00:34:12
AlexR

try to define 2 different <dependency> tags with different versions and scopes. Use tag <scope>test</scope> inside dependency for tests and <scope>compile</scope> for compilation.

It's a really bad idea to have two different versions for compile and test dependency:

Your non-test code might rely on behavior of the newer JAR and fail when using classes of the older JAR. When you use the older JAR in your tests, the non-test code would fail with the old JAR.

Otherwise you could have used the older JAR anywhere, with the same version... If you get both JAR versions into your classpath, you cannot know which one gets picked up when running your tests. That's also a bad idea.

Hence you should get non-test and test to the same JAR version dependency.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!