【问题标题】:merge strategy not working for deduplicate issue with sbt-assembly合并策略不适用于 sbt-assembly 的重复数据删除问题
【发布时间】:2014-12-06 02:41:03
【问题描述】:

我在尝试运行 assembly 时遇到重复数据删除错误。我为我的合并策略使用了许多不同的方法来尝试解决问题,但它们似乎都不起作用..

错误的sbt输出

[warn] Merging 'META-INF\DUMMY.DSA' with strategy 'discard'
[warn] Merging 'META-INF\DUMMY.SF' with strategy 'discard'
[warn] Merging 'META-INF\ECLIPSEF.SF' with strategy 'discard'
[warn] Merging 'META-INF\INDEX.LIST' with strategy 'discard'
[warn] Merging 'META-INF\MANIFEST.MF' with strategy 'discard'
[warn] Merging 'META-INF\services\java.sql.Driver' with strategy 'filterDistinctLines'
[warn] Merging 'META-INF\spring.handlers' with strategy 'filterDistinctLines'
[warn] Merging 'META-INF\spring.schemas' with strategy 'filterDistinctLines'
[debug] Merging 'META-INF\spring.tooling' with strategy 'deduplicate'
java.lang.RuntimeException: deduplicate: different file contents found in the following:
C:\Users\Matthew\.ivy2\cache\org.springframework\spring-jdbc\jars\spring-jdbc-4.0.5.RELEASE.jar:META-INF/spring.tooling
C:\Users\Matthew\.ivy2\cache\org.springframework\spring-beans\jars\spring-beans-4.0.5.RELEASE.jar:META-INF/spring.tooling
C:\Users\Matthew\.ivy2\cache\org.springframework\spring-tx\jars\spring-tx-4.0.5.RELEASE.jar:META-INF/spring.tooling

和 build.scala

import com.mojolly.scalate.ScalatePlugin.ScalateKeys._
import com.mojolly.scalate.ScalatePlugin._
import org.scalatra.sbt._
import sbt.Keys._
import sbt._
import sbtassembly.Plugin._
import sbtassembly.Plugin.AssemblyKeys._

object ScalatraBuild extends Build {
    val Organization = "com.my.myproject"
    val Name = "myproject"
    val Version = "0.1.0-SNAPSHOT"
    val ScalaVersion = "2.11.1"
    val ScalatraVersion = "2.3.0"
    val port = SettingKey[Int]("port")
    val Conf = config("container")

    lazy val project = Project(
        "myproject-platform",
        file("."),
        settings = Defaults.defaultConfigs ++ ScalatraPlugin.scalatraWithJRebel ++ net.virtualvoid.sbt.graph.Plugin.graphSettings ++ scalateSettings ++ assemblySettings ++ Seq(
            port in Conf := 8080,
            organization := Organization,
            name := Name,
            version := Version,
            scalaVersion := ScalaVersion,
            resolvers ++= Seq("Sonatype OSS Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/",
                "RoundEights" at "http://maven.spikemark.net/roundeights",
                Resolver.sonatypeRepo("releases")),
            libraryDependencies ++= Seq(
                "org.scala-lang" % "scala-compiler" % "2.11.1",
                "org.scalatra" %% "scalatra" % ScalatraVersion,
                "org.scalatra" %% "scalatra-scalate" % ScalatraVersion,
                "org.scalatra" %% "scalatra-scalatest" % ScalatraVersion % "test",
                "org.scalatra" %% "scalatra-auth" % "2.3.0",
                "org.scalatra" %% "scalatra-json" % "2.3.0",
                "org.json4s" %% "json4s-jackson" % "3.2.10",
                "org.json4s" %% "json4s-ext" % "3.2.10",
                "org.json4s" %% "json4s-core" % "3.2.10",
                "com.chuusai" %% "shapeless" % "2.0.0",
                "com.github.julien-truffaut" %% "monocle-core" % "0.5.1",
                "com.github.julien-truffaut" %% "monocle-generic" % "0.5.1",
                "com.github.julien-truffaut" %% "monocle-macro" % "0.5.1",
                "com.roundeights" %% "mailgun-scala" % "0.2",
                "com.roundeights" %% "scalon" % "0.2",
                "net.databinder.dispatch" %% "dispatch-core" % "0.11.1",
                "com.escalatesoft.subcut" %% "subcut" % "2.1",
                "com.typesafe" % "config" % "1.2.1",
                "ch.qos.logback" % "logback-classic" % "1.0.13" % "runtime",
                "org.codehaus.janino" % "janino" % "2.6.1",
                "org.eclipse.jetty" % "jetty-webapp" % "8.1.8.v20121106" % "container;compile",
                "org.apache.derby" % "derby" % "10.10.1.1",
                "c3p0" % "c3p0" % "0.9.1.2",
                "org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "compile;container;provided;test" artifacts (Artifact("javax.servlet", "jar", "jar")),
                "com.googlecode.mapperdao" %% "mapperdao" % "1.0.1",
                "mysql" % "mysql-connector-java" % "5.1.18",
                "commons-dbcp" % "commons-dbcp" % "1.4",
                "com.stripe" % "stripe-java" % "1.18.0"
            ),
            mergeStrategy in assembly <<= (mergeStrategy in assembly) {
                (old) => {
                    case PathList(xs@_*) if xs.last endsWith ".tooling" => MergeStrategy.first
                    case PathList("META-INF", "spring.tooling") => MergeStrategy.first
                    case PathList("META-INF", xs @ _*) =>
                    (xs map {_.toLowerCase}) match {
                        case "spring.tooling" :: Nil => MergeStrategy.first
                    }
                    case x => old(x)
                }
            },
                scalateTemplateConfig in Compile <<=(sourceDirectory in Compile) { base =>
                Seq(
                    TemplateConfig(
                        base / "webapp" / "WEB-INF" / "templates",
                        Seq.empty, /* default imports should be added here */
                        Seq.empty, /* add extra bindings here */
                        Some("templates")
                    )
                )
            }
        )
    )
}

如您所见,我尝试了一些不同的方法,但没有一个与案例相符。请问我能得到一些帮助吗?

【问题讨论】:

    标签: scala sbt scalatra sbt-assembly


    【解决方案1】:

    试试这个

      case x if x.endsWith("spring.tooling") => MergeStrategy.last
    

    对我来说构建文件看起来不错,但你可以尝试添加'println'语句来查看是否真的使用了自定义合并策略,也许 sbt-assembly 没有看到它

    【讨论】:

    • 我在case x 匹配中添加了println 语句,但它没有触发...您认为将设置移动到项目根目录中自己的assembly.sbt 会有所帮助吗?毕竟这是一个单一的模块项目..
    【解决方案2】:

    我在项目的根目录中使用了assembly.sbt 文件,但在build.scala 中指定了合并策略设置。一旦我将设置移动到此文件中,一切正常。

    【讨论】:

      猜你喜欢
      • 2013-01-25
      • 2019-06-03
      • 2014-09-28
      • 2016-07-10
      • 2017-05-21
      • 2019-01-31
      • 2014-11-01
      • 2015-12-27
      • 2019-01-11
      相关资源
      最近更新 更多