Sbt 排除依赖冲突详细解析

版权声明:本文为博主原创文章,出处为 http://blog.csdn.net/silentwolfyh https://blog.csdn.net/silentwolfyh/article/details/80820511

1.Sbt 依赖树

参考:
dependencyGraph sbt plugin
https://github.com/jrudolph/sbt-dependency-graph

安装插件
建立文件:./.sbt/1.0/plugins/plugins.sbt
添加内容:addSbtPlugin(“net.virtual-void” % “sbt-dependency-graph” % “0.9.0”)

插件启动
sbt:graphPlatform> dependencyTree
其他命令:https://github.com/jrudolph/sbt-dependency-graph#main-tasks

问题:
项目中要的是hbase1.2.6版本的包,确出现了hbase1.1.1,原因是hive-jdbc和hive-cli间接依赖hbase1.1.1
sbt的依赖包如下所示:

  "org.apache.hbase" % "hbase-client" % "1.2.6",
  "org.apache.hbase" % "hbase-common" % "1.2.6",
  "org.apache.hbase" % "hbase-server" % "1.2.6",
  "org.apache.hbase" % "hbase-protocol" % "1.2.6",
  "org.apache.hive" % "hive-jdbc" % "2.3.2",
  "org.apache.hive" % "hive-cli" % "2.3.2",

项目中依赖截图如下所示:
idea–>File–>Project Structure–>Libraries
这里写图片描述

解决依赖:
1)使用依赖树:sbt->project project_name->dependencyTree
2)查看相互依赖:sbt->project project_name->whatDependsOn org.apache.hbase hbase-annotations 1.1.1

依赖从下往上看“com.jd.jr:graph_importer_2.11:1.0-SNAPSHOT”依赖–>“org.apache.hive:hive-cli:2.3.2”依赖–>“org.apache.hive:hive-service:2.3.2”依赖–>“org.apache.hive:hive-llap-server:2.3.2”依赖–>“org.apache.hbase:hbase-server:1.1.1”

找到问题了,需要在“org.apache.hive:hive-cli:2.3.2”排除“org.apache.hbase:hbase-server:1.1.1”

sbt:graph_importer> whatDependsOn org.apache.hbase hbase-server 1.1.1
[info] org.apache.hbase:hbase-server:1.1.1 (evicted by: 1.2.6)
[info]   +-com.jd.jr:graph_importer_2.11:1.0-SNAPSHOT [S]
[info]   +-org.apache.hive:hive-llap-server:2.3.2
[info]     +-org.apache.hive:hive-service:2.3.2
[info]       +-org.apache.hive:hive-cli:2.3.2
[info]       | +-com.jd.jr:graph_importer_2.11:1.0-SNAPSHOT [S]
[info]       |
[info]       +-org.apache.hive:hive-jdbc:2.3.2
[info]         +-com.jd.jr:graph_importer_2.11:1.0-SNAPSHOT [S]
[info]

这里写图片描述

3)其余三个不需要的Jar包参考第二步
sbt依赖的处理后展示

扫描二维码关注公众号,回复: 3763374 查看本文章
  "org.apache.hbase" % "hbase-client" % "1.2.6",
  "org.apache.hbase" % "hbase-common" % "1.2.6",
  "org.apache.hbase" % "hbase-server" % "1.2.6",
  "org.apache.hbase" % "hbase-protocol" % "1.2.6",

  "org.apache.hive" % "hive-jdbc" % "2.3.2"
    exclude("org.apache.hbase", "hbase-protocol")
    exclude("org.apache.hbase", "hbase-client")
    exclude("org.apache.hbase", "hbase-common")
    exclude("org.apache.hbase", "hbase-service"),
  "org.apache.hive" % "hive-cli" % "2.3.2"
    exclude("org.apache.hbase", "hbase-protocol")
    exclude("org.apache.hbase", "hbase-client")
    exclude("org.apache.hbase", "hbase-common")
    exclude("org.apache.hbase", "hbase-service"),

4)sbt中先“clean”再“compile”.(其中compile包括了update)
项目中依赖截图如下所示:
这里写图片描述

5)sbt依赖树输出到本地文件命令
graph_importer是项目名称

sbt "project graph_importer" dependencyTree >> dependencyTree.txt

猜你喜欢

转载自blog.csdn.net/silentwolfyh/article/details/80820511
sbt