SBT 与 Akka 未解决的依赖关系

SBT unresolved dependecie with Akka

我刚接触Scala、Akka和SBT,所以这个问题让我很头疼!我正在研究 Akka in Action 一书,作者在其中提供了有关 Github 的示例: https://github.com/RayRoestenburg/akka-in-action 在存储库的干净克隆上,我试图查看 chapter-cluster.

中的示例

如书中所述,首先要做的是在本地机器上启动一个种子节点:

sbt -DHOST=127.0.0.1 -DPORT=2551

我试图安装另一个 Scala 版本,运行 它具有 root 权限,但没有成功。在我的理解中,SBT 应该处理所有版本控制的事情并下载指定的包。

错误信息是这样的:

[info] Loading global plugins from /home/sfink/.sbt/0.13/plugins
[info] Loading project definition from /home/sfink/IdeaProjects/akka-in-action/chapter-cluster/project
[info] Updating {file:/home/sfink/IdeaProjects/akka-in-action/chapter-cluster/project/}chapter-cluster-build...
[info] Resolving org.scala-sbt#compiler-interface;0.13.1 ...
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: org.scala-lang#scala-library;2.10.4: configuration not found in org.scala-lang#scala-library;2.10.4: 'master(compile)'. Missing configuration: 'compile'. It was required from org.scalactic#scalactic_2.10;2.2.1 compile
[warn]  :: org.scala-lang#scala-reflect;2.10.4: configuration not found in org.scala-lang#scala-reflect;2.10.4: 'master(compile)'. Missing configuration: 'compile'. It was required from org.scalactic#scalactic_2.10;2.2.1 compile
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
sbt.ResolveException: unresolved dependency: org.scala-lang#scala-library;2.10.4: configuration not found in org.scala-lang#scala-library;2.10.4: 'master(compile)'. Missing configuration: 'compile'. It was required from org.scalactic#scalactic_2.10;2.2.1 compile
unresolved dependency: org.scala-lang#scala-reflect;2.10.4: configuration not found in org.scala-lang#scala-reflect;2.10.4: 'master(compile)'. Missing configuration: 'compile'. It was required from org.scalactic#scalactic_2.10;2.2.1 compile
    at sbt.IvyActions$.sbt$IvyActions$$resolve(IvyActions.scala:213)
    at sbt.IvyActions$$anonfun$update.apply(IvyActions.scala:122)
    at sbt.IvyActions$$anonfun$update.apply(IvyActions.scala:121)
    at sbt.IvySbt$Module$$anonfun$withModule.apply(Ivy.scala:116)
    at sbt.IvySbt$Module$$anonfun$withModule.apply(Ivy.scala:116)
    at sbt.IvySbt$$anonfun$withIvy.apply(Ivy.scala:104)
    at sbt.IvySbt.sbt$IvySbt$$action(Ivy.scala:51)
    at sbt.IvySbt$$anon.call(Ivy.scala:60)
    at xsbt.boot.Locks$GlobalLock.withChannel(Locks.scala:98)
    at xsbt.boot.Locks$GlobalLock.xsbt$boot$Locks$GlobalLock$$withChannelRetries(Locks.scala:81)
    at xsbt.boot.Locks$GlobalLock$$anonfun$withFileLock.apply(Locks.scala:102)
    at xsbt.boot.Locks$GlobalLock$$anonfun$withFileLock.apply(Locks.scala:102)
    at xsbt.boot.Using$.withResource(Using.scala:11)
    at xsbt.boot.Using$.apply(Using.scala:10)
    at xsbt.boot.Locks$GlobalLock.withFileLock(Locks.scala:102)
    at xsbt.boot.Locks$GlobalLock.ignoringDeadlockAvoided(Locks.scala:62)
    at xsbt.boot.Locks$GlobalLock.withLock(Locks.scala:52)
    at xsbt.boot.Locks$.apply0(Locks.scala:38)
    at xsbt.boot.Locks$.apply(Locks.scala:28)
    at sbt.IvySbt.withDefaultLogger(Ivy.scala:60)
    at sbt.IvySbt.withIvy(Ivy.scala:101)
    at sbt.IvySbt.withIvy(Ivy.scala:97)
    at sbt.IvySbt$Module.withModule(Ivy.scala:116)
    at sbt.IvyActions$.update(IvyActions.scala:121)
    at sbt.Classpaths$$anonfun$sbt$Classpaths$$work.apply(Defaults.scala:1161)
    at sbt.Classpaths$$anonfun$sbt$Classpaths$$work.apply(Defaults.scala:1159)
    at sbt.Classpaths$$anonfun$doWork$$anonfun.apply(Defaults.scala:1182)
    at sbt.Classpaths$$anonfun$doWork$$anonfun.apply(Defaults.scala:1180)
    at sbt.Tracked$$anonfun$lastOutput.apply(Tracked.scala:35)
    at sbt.Classpaths$$anonfun$doWork.apply(Defaults.scala:1184)
    at sbt.Classpaths$$anonfun$doWork.apply(Defaults.scala:1179)
    at sbt.Tracked$$anonfun$inputChanged.apply(Tracked.scala:45)
    at sbt.Classpaths$.cachedUpdate(Defaults.scala:1187)
    at sbt.Classpaths$$anonfun$updateTask.apply(Defaults.scala:1152)
    at sbt.Classpaths$$anonfun$updateTask.apply(Defaults.scala:1130)
    at scala.Function1$$anonfun$compose.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219.apply(TypeFunctions.scala:42)
    at sbt.std.Transform$$anon.work(System.scala:64)
    at sbt.Execute$$anonfun$submit$$anonfun$apply.apply(Execute.scala:237)
    at sbt.Execute$$anonfun$submit$$anonfun$apply.apply(Execute.scala:237)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
    at sbt.Execute.work(Execute.scala:244)
    at sbt.Execute$$anonfun$submit.apply(Execute.scala:237)
    at sbt.Execute$$anonfun$submit.apply(Execute.scala:237)
    at sbt.ConcurrentRestrictions$$anon$$anonfun.apply(ConcurrentRestrictions.scala:160)
    at sbt.CompletionService$$anon.call(CompletionService.scala:30)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:748)
[error] (*:update) sbt.ResolveException: unresolved dependency: org.scala-lang#scala-library;2.10.4: configuration not found in org.scala-lang#scala-library;2.10.4: 'master(compile)'. Missing configuration: 'compile'. It was required from org.scalactic#scalactic_2.10;2.2.1 compile
[error] unresolved dependency: org.scala-lang#scala-reflect;2.10.4: configuration not found in org.scala-lang#scala-reflect;2.10.4: 'master(compile)'. Missing configuration: 'compile'. It was required from org.scalactic#scalactic_2.10;2.2.1 compile

更新 1: 这是 build.sbt 文件的内容:

name := "words-cluster"

version := "1.0"

scalaVersion := "2.11.7"

organization := "com.manning"

libraryDependencies ++= {
  val akkaVersion = "2.4.14"
  Seq(
    "com.typesafe.akka"       %% "akka-actor"                        % akkaVersion,
    "com.typesafe.akka"       %% "akka-slf4j"                        % akkaVersion,
    "com.typesafe.akka"       %% "akka-remote"                       % akkaVersion,
    "com.typesafe.akka"       %% "akka-cluster"                      % akkaVersion,
    "com.typesafe.akka"       %% "akka-multi-node-testkit"           % akkaVersion   % "test",
    "com.typesafe.akka"       %% "akka-testkit"                      % akkaVersion   % "test",
    "org.scalatest"           %% "scalatest"                         % "3.0.0"       % "test",
    "com.typesafe.akka"       %% "akka-slf4j"                        % akkaVersion,
    "ch.qos.logback"          %  "logback-classic"                   % "1.0.10"
  )
}

// Assembly settings
mainClass in Global := Some("aia.cluster.words.Main")

assemblyJarName in assembly := "words-node.jar"

知道出了什么问题吗?

试试这个作为你的 build.sbt:

name := "words-cluster"

version := "1.0"

scalaVersion := "2.11.8"

organization := "com.manning"

libraryDependencies ++= {
  val akkaVersion = "2.4.14"
  Seq(
    "com.typesafe.akka"       %% "akka-actor"                        % akkaVersion,
    "com.typesafe.akka"       %% "akka-slf4j"                        % akkaVersion,
    "com.typesafe.akka"       %% "akka-remote"                       % akkaVersion,
    "com.typesafe.akka"       %% "akka-cluster"                      % akkaVersion,
    "com.typesafe.akka"       %% "akka-multi-node-testkit"           % akkaVersion   % "test",
    "com.typesafe.akka"       %% "akka-testkit"                      % akkaVersion   % "test",
    "org.scalatest"           %% "scalatest"                         % "3.0.1"       % "test" exclude("org.scala-lang.modules", "scala-xml_2.11"),
    "com.typesafe.akka"       %% "akka-slf4j"                        % akkaVersion,
    "ch.qos.logback"          %  "logback-classic"                   % "1.1.7"
  )
}

// Assembly settings
mainClass in Global := Some("aia.cluster.words.Main")

assemblyJarName in assembly := "words-node.jar"

我更新了 scala、logging 和 scalatest 版本

看来我用的sbt版本是错误的!升级到 sbt-0.13.15 后编译 运行 正确。

感谢您的帮助!