Maven依赖不兼容的库类 [英] Maven dependency incompatible library class

查看:58
本文介绍了Maven依赖不兼容的库类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序定义了一个外部库 jar 依赖

My application is defined with an external library jar dependency

<dependency>
    <groupId>com.lib</groupId>
    <artifactId>Encoder</artifactId>
</dependency>

它有两个版本 1.0 和 2.0.库中拥有的类在这些版本之间的包结构中得到了更新,如下所示.

It has two versions 1.0 and 2.0. A class owned in the library got updated in its package structure between these versions as below.

1.0 -- a.b.c.模板

1.0 -- a.b.c.Template

2.0 -- x.y.z.模板

2.0 -- x.y.z.Template

我的应用程序中使用的另一个名为Helper"的依赖项也包含上述 Encoder 库,但版本为 1.0.

Another dependency called 'Helper' used in my application also contains the above stated Encoder library, but with version 1.0.

现在,我的应用程序使用编码器"库版本 2.0 以及助手"依赖项进行定义.

Now, my application is defined with 'Encoder' library version 2.0 along with 'Helper' dependency.

我对Encoder库的应用使用

My application usage of Encoder library

import x.y.z.Template
..

Encoder 库的 'Helper' 依赖使用

The 'Helper' dependency usage of Encoder library

import a.b.c.Template
..

代码构建失败,找不到类文件错误,如下所示.

The code build is failing with class file not found error as like below.

无法访问 a.b.c.Template 类文件,因为找不到 a.b.c.Template

cannot access a.b.c.Template class file for a.b.c.Template not found

感谢您帮助找到相同的解决方案.提前致谢!

Appreciate your help on finding a solution for the same. Thanks in advance!

推荐答案

最好是通过仔细选择依赖版本来避免上述情况,直到一切顺利运行.

The best is to avoid above situation by carefully picking dependency versions until everything runs smoothly.

如果这太难了,你可以看看 maven-shade-plugin,它允许你重新定位合并到依赖项中的包.

If this is too difficult, you can have a look at the maven-shade-plugin, which allows you to relocate packages that are merged into a dependency.

这篇关于Maven依赖不兼容的库类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆