Tuesday, April 24, 2018

Gradle / Maven Dependency Conflict Issue - 定位冲突的根本思路

Resolving Maven Dependency Conflict Problem In Intellij, 这次从根本上记录下排查dependency conflict的debug思路。
一般出现冲突的现象是,在服务器端提示如下错误信息:
2018-04-25 11:09:08,624 [ERROR] [http-nio-8591-exec-8] (org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet]) - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: com.google.protobuf.AbstractMessageLite$Builder.addAll(Ljava/lang/Iterable;Ljava/util/List;)V] with root cause
java.lang.NoSuchMethodError: com.google.protobuf.AbstractMessageLite$Builder.addAll(Ljava/lang/Iterable;Ljava/util/List;)V
...
本example中可见是com.google.protobuf.AbstractMessageLite$Builder.addAll方法无法找到。既然zip包里存在冲突,则先解压缩,navigate到所有jar包所在目录,执行如下command:
ll | awk '{print $9}' | xargs -I %%% sh -c 'echo "current_jar="%%%; jar tf %%%' > dep.txt
目的是将所有jar包的所有class信息都print出来。然后找到AbstractMessageLite类所在的jar包(如果存在冲突,一定有至少两个jar包存在此类)。由此找到hive-exec-2.3.2.jar和protobuf-java-3.5.1.jar两个包都存在此类。Apply javap -classpath <jar_file> 'com.google.protobuf.AbstractMessageLite$Builder' to both jar files respectively, 可以得到如下部分log:
~/Downloads/kuaishou-lineage-webapp-1.0-SNAPSHOT/lib $ javap -classpath protobuf-java-3.5.1.jar 'com.google.protobuf.AbstractMessageLite$Builder'
Compiled from "AbstractMessageLite.java"
public abstract class com.google.protobuf.AbstractMessageLite$Builder<MessageType extends com.google.protobuf.AbstractMessageLite<MessageType, BuilderType>, BuilderType extends com.google.protobuf.AbstractMessageLite$Builder<MessageType, BuilderType>> implements com.google.protobuf.MessageLite$Builder {
...
protected static <T> void addAll(java.lang.Iterable<T>, java.util.Collection<? super T>);
protected static <T> void addAll(java.lang.Iterable<T>, java.util.List<? super T>);
...
}
~/Downloads/kuaishou-lineage-webapp-1.0-SNAPSHOT/lib $ javap -classpath hive-exec-2.3.2.jar 'com.google.protobuf.AbstractMessageLite$Builder'
Compiled from "AbstractMessageLite.java"
public abstract class com.google.protobuf.AbstractMessageLite$Builder<BuilderType extends com.google.protobuf.AbstractMessageLite$Builder> implements com.google.protobuf.MessageLite$Builder {
...
protected static <T> void addAll(java.lang.Iterable<T>, java.util.Collection<? super T>);
...
}
可见hive-exec-2.3.2.jar中少了一种addAll接口。只需在maven/gradle中将对应的dependency排除即可, Khalas.

No comments:

Post a Comment