通过使用sbt和sbt-assembly创建一个胖jar来解决eclipselink的依赖关系?

时间:2014-02-18 18:17:34

标签: scala eclipselink sbt sbt-assembly

我尝试用scala和EclipseLink JPA为我的项目创建一个带有sbt和sbt-assembly插件的胖jar,但是程序集命令失败了,因为eclipse.inf文件会找到两次。

> assembly
[info] Including from cache: commonj.sdo-2.1.1.jar
[info] Including from cache: javax.persistence-2.1.0.jar
[info] Including from cache: scala-library.jar
[info] Including from cache: eclipselink-2.5.1.jar
[info] Run completed in 38 milliseconds.
[info] Checking every *.class/*.jar file's SHA-1.
[info] Merging files...
[warn] Merging 'org\eclipse\persistence\descriptors\copying' with strategy 'rename'
[warn] Merging 'META-INF\MANIFEST.MF' with strategy 'discard'
[trace] Stack trace suppressed: run last *:assembly for the full output.
[error] (*:assembly) deduplicate: different file contents found in the following:
[error] C:\Users\u987\WebApps\gr\lib_managed\jars\org.eclipse.persistence\javax.persistence\jav    ax.persistence-2.1.0.jar:META-INF/eclipse.inf 
[error] C:\Users\u987\WebApps\gr\lib_managed\jars\org.eclipse.persistence\commonj.sdo\commonj.sdo-2.1.1.jar:META-INF/eclipse.inf

我的build.sbt看起来像:

import AssemblyKeys._

name := "TelegramReceiver"

version := "0.1"

scalaVersion := "2.10.3"

retrieveManaged in ThisBuild := true

libraryDependencies ++= Seq(
  "org.scalatest" % "scalatest_2.10" % "2.0" % "test",
  "org.eclipse.persistence" % "eclipselink" % "2.5.1" 
)

我尝试使用sbt程序集插件中的mergeStrategy来解决问题,但它不起作用。我使用sbt 0.13.1。

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

您可以在设置中添加如下自定义合并策略:

  mergeStrategy in assembly <<= (mergeStrategy in assembly) { (old) =>
  {
    case PathList("eclipse.inf") => MergeStrategy.rename // use any of the available strategies like `first`
    case x => old(x)
  }}

有关详细信息,请参阅this doc