[英]Java/Maven how to use a dependency that uses an older version of another dependency that is already used in the project
In my project we use the version 2.9.0 of jackson-databind.在我的项目中,我们使用 2.9.0 版的 jackson-databind。 I want to use a maven dependency ( https://github.com/Jaspersoft/jrs-rest-java-client ), but it needs to use an older version of jackson-databind, because in more recents version they remove a method that the dependency calls (the exception "NoSuchMethod" is raised).我想使用 maven 依赖项( https://github.com/Jaspersoft/jrs-rest-java-client ),但它需要使用旧版本的jackson-databind,因为在最近的版本中,他们删除了一种方法依赖调用(引发异常“NoSuchMethod”)。
What to do in this case?在这种情况下该怎么办? Obviously I cannot downgrade the jackson-databind version we use in the project for other things just to please this sole dependency.显然我不能为了满足这个唯一的依赖而降级我们在项目中使用的 jackson-databind 版本。
Is there a way to keep using the recent version in my project, but make the dependency that needs the older version use the older version?有没有办法在我的项目中继续使用最新版本,但让需要旧版本的依赖项使用旧版本? In my opinion that would be the perfect solution, but I get the feeling it doesn't work that way.在我看来,这将是一个完美的解决方案,但我觉得它不是那样工作的。
Take a look at the Maven Shade Plugin: http://maven.apache.org/plugins/maven-shade-plugin/index.html Take a look at the Maven Shade Plugin: http://maven.apache.org/plugins/maven-shade-plugin/index.html
It allows you to rename the package of a version它允许您重命名一个版本的 package
Even if you find a solution to have two versions of the same dependency included in your project.即使您找到了一个解决方案,可以在您的项目中包含相同依赖项的两个版本。 You still have the problem, that when running the application in one JVM the classloader will not know which version of class is necessary now so it will load and provide the first class thats found in the class-loader-hierarchy.您仍然有问题,当在一个 JVM 中运行应用程序时,类加载器将不知道现在需要哪个版本的 class,因此它将加载并提供在类加载器中找到的第一个 class。 So you can not use two Versions of one Class in the same ClassLoader.所以你不能在同一个 ClassLoader 中使用一个 Class 的两个版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.