In my case, I ran into this error this way. pom.xml
of my project defined two dependencies A
and B
. And both A
and B
defined dependency on same artifact (call it C
) but different versions of it (C.1
and C.2
). When this happens, for each class in C
maven can only select one version of the class from the two versions (while building an uber-jar). It will select the "nearest" version based on its dependency mediation rules and will output a warning "We have a duplicate class..." If a method/class signature changes between the versions, it can cause a java.lang.IncompatibleClassChangeError
exception if the incorrect version is used at runtime.
Advanced: If A
must use v1 of C
and B
must use v2 of C
, then we must relocate C
in A
and B
's poms to avoid class conflict (we have a duplicate class warning) when building the final project that depends on both A
and B
.