简体   繁体   English

Shade(重定位)传递依赖的一个版本,而不是另一个版本

[英]Shade (relocate) one version of a transitive dependency, but not the other

I've got a Maven project that contains two dependencies, A and B . 我有一个包含两个依赖项AB的Maven项目。 Each of these depends transitively on C , but they depend on different versions of C . 这些中的每一个都依赖于C ,但它们依赖于不同版本的C. Let's say that A depends on C version 1, and B depends on C version 2. 假设A取决于C版本1, B取决于C版本2。

Unfortunately, A is not bytecode-compatible with version 2, nor B with version 1. (As it happens, A is source-compatible with version 2, but I don't think that will help us here.) 不幸的是, A与版本2不是字节码兼容,也不是版本1的B. (碰巧, A与版本2 源代码兼容 ,但我认为这不会对我们有所帮助。)

This means that I need both versions of the transitive dependency in my project, and I need A to use version 1, and B to use version 2. 这意味着我在项目中需要两个版本的传递依赖项,我需要A使用版本1, B需要使用版本2。

Is there a way of doing this? 有办法做到这一点吗?

I had assumed that I would need to use the shade plugin to relocate the package name of A and all its dependencies, but this doesn't seem to be possible. 我曾假设我需要使用shade插件来重新定位A的包名及其所有依赖项,但这似乎不可能。 If I shade A , its dependencies don't get shaded, and it still picks up version 2, and fails to run. 如果我遮蔽A ,它的依赖关系不会被遮挡,它仍然会选择版本2,并且无法运行。

Create another project wrapper A named A-wrapper . 创建另一个项目包装器A名为A-wrapper Relocate C in A-wrapper . A-wrapper重新定位C Then in your main project, depends on A-wrapper and B . 然后在你的主项目中,依赖于A-wrapperB

I've met a similar problem on pb2 and pb3 and it is resolved using this way. 我在pb2和pb3上遇到了类似的问题,并且使用这种方式解决了它。 https://stackoverflow.com/a/41394239/1395722 https://stackoverflow.com/a/41394239/1395722

Assuming dependency A requires v1 of C and dependency B requires v2 of C . 假设依赖关系A需要C的v1,而依赖关系B需要C的v2 You can create an uber jar of A containing v1 of C but changing the packaging using shade plugin, Example jar A has contents of C with new packaging "v1.c.something" . 您可以创建一个包含v的C的超级罐,但是使用shade插件更改包装,示例jar A的内容为C,新包装为“v1.c.something” Do the same for B, so jar B has contents of C with new packaging "v2.c.something" . 对B做同样的事情,因此jar B的内容为C,新包装为“v2.c.something” You need to include only the conflicting dependencies not all. 您只需要包含冲突的依赖项,而不是全部。

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

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