解决通过SBT程序集创建JAR的依赖性 [英] Resolving Dependencies in creating JAR through SBT assembly

查看:245
本文介绍了解决通过SBT程序集创建JAR的依赖性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个大的Jar文件.试图使用 SBT ASSEMBLY 的用户.我从 GitHub 安装了sbt-assembly和这个

I want to create a big Jar file. for which am trying to use SBT ASSEMBLY. I installed sbt-assembly from GitHub and this answer. When I ran sbt assembly, I got this error:

java.lang.RuntimeException: deduplicate: different file contents found in the following:
/home/UserName/.ivy2/cache/org.eclipse.jetty.orbit/javax.servlet/orbits/javax.servlet-2.5.0.v201103041518.jar:javax/servlet/SingleThreadModel.class
/home/UserName/.ivy2/cache/org.mortbay.jetty/servlet-api/jars/servlet-api-2.5-20081211.jar:javax/servlet/SingleThreadModel.class

为解决此问题,我遵循了User的README页面,这是他建议的代码.

To solve this, I followed User's README page and this is the code he suggests.

mergeStrategy in assembly <<= (mergeStrategy in assembly) { (old) =>
  {
    case PathList("org", "apache", xs @ _*) => MergeStrategy.last
    case PathList("javax", "servlet", xs @ _*) => MergeStrategy.last
    case PathList("com", "esotericsoftware", xs @ _*) => MergeStrategy.last
    case PathList("project.clj") => MergeStrategy.last
    case PathList("overview.html") => MergeStrategy.last
    case x => old(x)
  }
}

即使添加此代码后,我也会遇到前面提到的相同错误.请让我知道我想念的东西.对此错误的任何帮助将不胜感激.谢谢!

Even after adding this code, I get the same error mentioned before. Please let me know what I am missing. Any help on this error will be appreciated. Thanks!

更新2:

根据给定的链接添加了排除规则

Added the exlusion rule as per the link given,

libraryDependencies ++= Seq("org.apache.spark" %% "spark-core" % "0.8.0-incubating","com.codahale" % "jerkson_2.9.1" % "0.5.0","org.skife.com.typesafe.config" % "typesafe-config" % "0.3.0").map(_.exclude("javax", "servlet"))

更新3:

我可以找到引起问题的库.

I can locate the library that is causing the issue.

| +-org.apache.avro:avro-ipc:1.7.4
| | +-io.netty:netty:3.4.0.Final (evicted by: 3.5.4.Final)
| | +-io.netty:netty:3.5.4.Final
...
...
| | +-org.mortbay.jetty:jetty-util:6.1.26
| | +-org.mortbay.jetty:jetty:6.1.26
| | | +-org.mortbay.jetty:jetty-util:6.1.26
| | | +-org.mortbay.jetty:servlet-api:2.5-20081211
| | | 
| | +-org.mortbay.jetty:servlet-api:2.5-20081211
| | +-org.slf4j:slf4j-api:1.7.2
...
... 
| +-org.eclipse.jetty:jetty-server:7.6.8.v20121106
| | +-org.eclipse.jetty.orbit:javax.servlet:2.5.0.v201103041518

更新4:修复

因此添加MergeStrategy确实解决了问题.即使我有很多依赖关系(超过10个),也分别为其中每个添加MergeStrategy解决了问题.

So adding MergeStrategy did solve the problem. Even though I had quite a few dependencies, more than 10, adding MergeStrategy for each one of them individually solved the issue.

推荐答案

我认为您正在尝试解决这些症状,但实际上问题不是汇编程序:您的项目在类路径上的两个不同版本中两次拥有一个库(javax.servlet).

I think you are trying to treat the symptoms, but your problem actually isn't assembly: Your project has a library twice in two different versions on the class path (javax.servlet).

如果这些版本是二进制兼容的(我不知道),那么可以通过排除构建文件中两个匹配项之一来解决问题 sbt-dependency-graph 插件)并尝试找到匹配的版本.

If these versions are binary compatible (which I don't know), you would be fine by excluding one of the two occurrences in your build file like so. If they incompatible, you will need to unroll your dependency graph (a good way to do this might be the sbt-dependency-graph plugin) and try to find matching versions.

在任何情况下,(至少暂时)将库保留在项目文件夹中可能很有用.如果将retrieveManaged in ThisBuild := true添加到sbt构建文件中,则所有库都将在<project-root>/lib_managed中找到.这使您可以查看实际上有哪些罐子.

In any case, it might be useful to (at least transitorily) keep the libraries in the project folder. If you add retrieveManaged in ThisBuild := true to your sbt build file, all the libraries will be found in <project-root>/lib_managed. This allows you to see which jars are actually there.

编辑:显示依赖关系图:

添加到project/plugins.sbt:

addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.7.4")

添加到build.sbt:

net.virtualvoid.sbt.graph.Plugin.graphSettings

然后运行sbt dependency-graph.

这篇关于解决通过SBT程序集创建JAR的依赖性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆