使用sbt 13.8,IntelliJ的最新scala插件,以及使用Scala 2.11.7的新SBT项目,我尝试添加一个库 - akka 2.4.2。关注this,我只需添加
libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.4.2"
但是我得到了一个未解决的依赖错误:
错误:导入SBT项目时出错:
[info]解析org.scala-sbt#tasks; 0.13.8 ......
[info]解析org.scala-sbt#tracking; 0.13.8 ......
[info]解析org.scala-sbt #cache; 0.13.8 ......
[info]解析org.scala-sbt#testing; 0.13.8 ......
[info]解析org.scala-sbt #test-agent; 0.13.8 ...
[info]解析org.scala-sbt #test-interface; 1.0 ...
[info]解析org.scala-sbt #main-settings; 0.13.8 ...
[info]解析org.scala-sbt#apply-macro; 0.13.8 ...
[info]解析org.scala-sbt#command; 0.13.8 ......
[info]解析org.scala-sbt#logic; 0.13.8 ......
[info]解析org.scala-sbt #precompiled-2_8_2; 0.13.8 ......
[info]解析org.scala-sbt #precompiled-2_9_2; 0.13.8 ...
[info]解析org.scala-sbt #precompiled-2_9_3; 0.13.8 ...
[trace]抑制堆栈跟踪:运行' last common / *:update'为了完整的输出。
[trace]堆栈跟踪被抑制:run' last common / *:ssExtractDependencies'为了完整的输出。
[trace]禁止堆栈跟踪:运行' last APP1 / *:ssExtractDependencies'为了完整的输出。
[error](common / *:update)sbt.ResolveException:unresolved dependency:com.typesafe.akka#akka actor_2.10; 2.4.2:not found
[error](common / *:ssExtractDependencies)sbt.ResolveException:unresolved dependency:com.typesafe.akka#akka-actor_2.10; 2.4.2:not found
[error](app1 / *:ssExtractDependencies)sbt.ResolveException: 未解决的依赖:com.typesafe.akka#akka-actor_2.10; 2.4.2:未找到
如果我将项目设置为2.11.7,为什么sbt会尝试查找akka-actor_2.10
?
更新:
明确说明版本,
libraryDependencies += "com.typesafe.akka" % "akka-actor_2.11" % "2.4.2"
工作但是你得到一个SBT项目导入警告:
[warn] Scala版本由库依赖项之一更新:
[warn]二进制版本(2.11)依赖org.scala-lang #scala-library; 2.11.7 [warn] in com.myorg #common $ sources_2.10; 1.0与scala二进制版本不同于项目(2.10) )。
[warn]具有相同组织/名称但版本不同的多个依赖项。为避免冲突,请选择一个版本: [警告] * org.scala-lang:scala-library:(2.11.7,2.10.4)...
编辑:
build.sbt
import Dependencies._
name := "coolApps"
version := "1.0"
scalaVersion := "2.11.7"
lazy val common = (project in file("common")).
settings(Commons.settings: _*).
settings(
libraryDependencies ++= commonDependencies
// dependencyOverrides += "org.scala-lang" % "scala-library" % scalaVersion.value
)
lazy val app1 = (project in file("app1")).
settings(Commons.settings: _*).
settings(
libraryDependencies ++= app1Dependencies
).
dependsOn(common)
Dependencies.scala
object Dependencies {
val akka = "com.typesafe.akka" %% "akka-actor" % "2.4.2"
val commonDependencies: Seq[ModuleID] = Seq(
akka
)
val app1Dependencies: Seq[ModuleID] = Seq()
}
Commons.scala
import sbt._
import Keys._
object Commons {
val coolAppVersion = "1.0"
val settings: Seq[Def.Setting[_]] = Seq(
organization := "com.company",
version := coolAppVersion,
scalacOptions := Seq("-unchecked", "-deprecation", "-encoding", "utf8"),
resolvers ++= Seq(
"Typesafe Releases" at "http://repo.typesafe.com/typesafe/releases/"
)
)
}
答案 0 :(得分:3)
在build.sbt中,您需要设置密钥
scalaVersion := "2.11.7"
如果你没有设置它,它将使用SBT本身使用的scala,这是一个2.10.x版本。