問題背景
項目需要解析hiveSQL,所以引入了hive-exec,但是引入hive-exec包後報出guava包衝突
解決思路
- maven依賴嘗試exclusion掉hive-exec的guava exclusion無效,還是有衝突,嘗試結果無效
- maven dependency:tree 發現hive-exec中guava版本爲14.0.1,嘗試修改項目中guava版本爲14, 即只用hive-exec裏的guava -->其他依賴包不兼容
- 類似問題:
https://stackoverflow.com/questions/56476380/unable-to-load-multimaps-when-added-dependency-with-apache-hive
https://issues.apache.org/jira/browse/HIVE-5733
解決方案:
- 需要拉hive源碼,修改hive-exec(在hive中叫ql的一個module)的pom.xml
- 把ql module下pom的guava inclusion刪掉(之前exclude不掉ql下guava,正是因此),如圖:
- 修改artifactId和引用到hive-exec的其他module的pom.xml
建議:sed -i -lr 命令替換相關pom依賴
具體步驟
hive-exec打包傳私服步驟:
- 修改pom 版本爲2.3.4(根據自己項目引用版本)
- 根pom註釋掉多餘不需要打包的,修改hive-exec的artifactId(因爲後續要上傳公司私服,避免與hive-exec本身衝突),
- include項刪掉guava,見上面的圖
- 打包hive: mvn clean package -Pdist -DskipTests
- 在ql包下ql/target/拿到hive-exec的包
- 上傳修改過artifactId的jar包到公司私服(打包修改爲你公司私服地址和版本等)比如:
mvn deploy:deploy-file -DgroupId=org.apache.hive -DartifactId=hive-exec-xxx -Dversion=2.3.4-SNAPSHOT -Dpackaging=jar -Durl=http://repo.xxxx.com/repositories/snapshots -DrepositoryId=xxxx-snapshot -Dfile=hive-exec-xxx-2.3.4.jar
- 修改你的項目依賴爲自己新上傳私服的hive-exec-xxx
- 重新打包項目,衝突問題解決~(注:如果hive-exec出現非guava衝突,比如:commons-lang commons-lang3的衝突也是一樣的解決方式,原因都是hive-exec include了這些依賴,即打包到項目中,所以exclusion不掉)