Maven dependency incompatible library class

天涯浪子 提交于 2020-07-09 17:46:28

问题


My application is defined with an external library jar dependency

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

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.Template

2.0 -- x.y.z.Template

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

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

My application usage of Encoder library

import x.y.z.Template
..

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.

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!


回答1:


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

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.



来源:https://stackoverflow.com/questions/60396734/maven-dependency-incompatible-library-class

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