对于我现有的项目,我正在从scalaVersion 2.10.5迁移到2.11.7和sbtVersion 1.13.9。
当前的迁移项目是销售,它有 Sales-common,Sales-read,Sales-write 模块。它有一个依赖项目核心。但是我没有Core项目代码我只发布了artefact jar(我有myapp-core-read_2.10-2.2.33.jar,2.10是Scala版本)。
我的项目看起来像这样
销售
common build.sbt read build.sbt write build.sbt build.sbt
到目前为止,scala 2.10.5的所有内容都可以正常使用。
更改版本后,我运行sbt clean
和sbt update
。我得到像这样的未解决的依赖问题:
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: mycompany#myapp-core-read_2.11;2.2.33: not found
[warn] :: mycomapny#myapp-core-write_2.11;2.2.33: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
我的销售buld.sbt 是:
name := "myapp-sales"
organization in ThisBuild := "com.mycompany"
scalaVersion in ThisBuild := "2.11.7"
//crossScalaVersions in Thisq
//Build := List("2.10.5", scalaVersion.value)
//crossPaths := false
scalacOptions in Compile in ThisBuild ++= Seq("-unchecked", "-deprecation", "-encoding", "utf8", "-language:postfixOps", "-language:implicitConVersions")
lazy val common = Project("myapp-sales-common", file("common"))
lazy val read = Project("myapp-sales-read", file("read")).configs(IntegrationTest).settings(Defaults.itSettings: _*).dependsOn(common, write)
lazy val write = Project("myapp-sales-write", file("write")).configs(IntegrationTest).settings(Defaults.itSettings: _*).dependsOn(common)
conflictWarning in ThisBuild := ConflictWarning.disable
parallelExecution in Test in ThisBuild := false
parallelExecution in IntegrationTest in ThisBuild := false
javacOptions in Compile in ThisBuild ++= Seq("-source", "1.6", "-target", "1.6")
//Remove SNAPSHOT check from the release process (for now until Squants gets a release)
releaseProcess := releaseProcess.value.filterNot(_ == ReleaseTransformations.checkSnapshotDependencies)
我的阅读模块 build.sbt :
libraryDependencies ++= Seq(
"com.mycompany" %% "myapp-core-read" % myappsales.CoreVersion % "compile", // disable using the Scala version in output paths and artifacts,
"com.mycompany" %% "myapp-core-write" % myappsales.CoreVersion % "compile",
"com.mycompany" %% "myapp-registration-common" % myappsales.RegistrationVersion % "compile",
"com.mycompany" %% "myapp-load-common" % myappsales.LoadVersion % "compile",
"com.mycompany" %% "myapp-core-write-test" % myappsales.CoreVersion % "it, test",
"com.mycompany" %% "myapp-core-test" % myappsales.CoreVersion % "it, test"
)
libraryDependencies ++= Seq(
"com.typesafe" % "config" % myappsales.TypeSafeConfigVersion % "compile",
"org.json4s" %% "json4s-native" % Versions.Json4s % "compile",
"io.spray" % "spray-routing" % Versions.Spray % "compile",
"com.typesafe.akka" %% "akka-actor" % Versions.Akka % "compile",
"com.typesafe.akka" %% "akka-remote" % Versions.Akka % "compile"
exclude ("io.netty", "netty")
)
//Assemby settings
test in assembly := {}
assemblyShadeRules in assembly := Seq(
ShadeRule.rename("play.api.libs.iteratee.**" -> "shade.play.api.libs.iteratee.@1")
.inLibrary("play" % "play-iteratees_2.10" % "2.1-RC2")
.inLibrary("org.reactivemongo" % "reactivemongo_2.10" % "0.8.1-SNAPSHOT"),
ShadeRule.rename("scala.concurrent.stm.**" -> "shade.scala.concurrent.stm.@1")
.inLibrary("org.scala-stm" % "scala-stm_2.10.0" % "0.6")
.inLibrary("play" % "play-iteratees_2.10" % "2.1-RC2")
)
assemblyMergeStrategy in assembly := {
case "application.conf" => MergeStrategy.concat
case path => MergeStrategy.defaultMergeStrategy(path)
}
//Make assembly a publishable artifact
artifact in (
Compile, assembly) := {
val art = (artifact in (Compile, assembly)).value
art.copy(`classifier` = Some("assembly"))
}
addArtifact(artifact in (Compile, assembly), assembly)
如何使用现有的myapp-core-read_2.10-2.2.33.jar jar?
答案 0 :(得分:3)
重要说明: Scala 2.10和2.11不是二进制兼容的,因此您必须重新编译您所依赖的模块
回答问题:
这似乎与SBT如何解决依赖关系有关。当你声明一个像这样的依赖:
"com.mycompany" %% "myapp-core-read" % myappsales.CoreVersion
声明中的%%
部分意味着SBT会自动将scala版本附加到库名称,因此您的依赖关系变为
group: com.mycompany
artifactId: myapp-core-read_2.11
version: `your version`
您的myapp-core-read
似乎未使用scala 2.11
进行编译,因此SBT无法找到正确的版本。
您可以使用%
并手动应用正确的后缀来避免这种情况,因此您的依赖关系将变为:
"com.mycompany" % "myapp-core-read_2.10" % myappsales.CoreVersion
话虽如此,我认为scala 2.10和2.11不是二进制兼容的,因此您可能需要使用2.11重新编译myapp-core-read
模块。