喷射微服务组件去重

Spray microservice assembly deduplicate

我正在使用此模板开发微服务:

http://www.typesafe.com/activator/template/activator-service-container-tutorial

我的sbt文件是这样的:

import sbt._
import Keys._

name := "activator-service-container-tutorial"

version := "1.0.1"

scalaVersion := "2.11.6"
crossScalaVersions := Seq("2.10.5", "2.11.6")

resolvers += "Scalaz Bintray Repo" at "https://dl.bintray.com/scalaz/releases"

libraryDependencies ++= {

    val containerVersion    = "1.0.1"
  val configVersion     = "1.2.1"
  val akkaVersion           = "2.3.9"
  val liftVersion               = "2.6.2"
  val sprayVersion          = "1.3.3"

  Seq(
    "com.github.vonnagy"    %%  "service-container" % containerVersion,
    "com.github.vonnagy"    %%  "service-container-metrics-reporting" % containerVersion,
    "com.typesafe"        %   "config"                   % configVersion,
    "com.typesafe.akka"     %%  "akka-actor"                 % akkaVersion exclude ("org.scala-lang" , "scala-library"),
    "com.typesafe.akka"     %%  "akka-slf4j"                 % akkaVersion exclude ("org.slf4j", "slf4j-api") exclude ("org.scala-lang" , "scala-library"),
    "ch.qos.logback"            %   "logback-classic"        % "1.1.3",
    "io.spray"                      %%  "spray-can"                  % sprayVersion,
    "io.spray"                      %%  "spray-routing"          % sprayVersion,
    "net.liftweb"               %%  "lift-json"                  % liftVersion,

    "com.typesafe.akka"     %%  "akka-testkit"           % akkaVersion   % "test",
    "io.spray"            %%  "spray-testkit"      % sprayVersion  % "test",
    "junit"               %   "junit"              % "4.12"        % "test",
    "org.scalaz.stream"   %%  "scalaz-stream"      % "0.7a"        % "test",
    "org.specs2"          %%  "specs2-core"        % "3.5"         % "test",
    "org.specs2"          %%  "specs2-mock"        % "3.5"         % "test",
    "com.twitter"         %% "finagle-http"        % "6.25.0",
    "com.twitter"         %% "bijection-util"      % "0.7.2"
  )
}

scalacOptions ++= Seq(
  "-unchecked",
  "-deprecation",
  "-Xlint",
  "-Ywarn-dead-code",
  "-language:_",
  "-target:jvm-1.7",
  "-encoding", "UTF-8"
)

crossPaths := false

parallelExecution in Test := false


assemblyJarName in assembly := "santo.jar"
mainClass in assembly := Some("Service")

项目编译正常! 但是当我 运行 组装时,终端显示如下:

[error] (*:assembly) deduplicate: different file contents found in the following:
[error] /path/.ivy2/cache/io.dropwizard.metrics/metrics-core/bundles/metrics-core-3.1.1.jar:com/codahale/metrics/ConsoleReporter.class
[error] /path/.ivy2/cache/com.codahale.metrics/metrics-core/bundles/metrics-core-3.0.1.jar:com/codahale/metrics/ConsoleReporter.class

我有什么选择可以修复它? 谢谢

问题似乎是依赖的传递依赖是由两个不同版本的 metrics-core 引起的。最好的办法是使用正确的库依赖关系,这样你最终会得到这个库的单一版本。如果很难找出依赖关系,请使用 https://github.com/jrudolph/sbt-dependency-graph

如果无法获得单一版本,那么您很可能会选择 exclude route。我假设,这仅在所有必需版本之间存在兼容性的情况下才有效。