akka Scala/SBT:“对象不是包”的成员,但该对象位于外部库中

btqmn9zl  于 2022-11-06  发布在  Scala
关注(0)|答案(1)|浏览(155)

在Scala 2.13.4/SBT 1.2.8项目中,类MyService.scala具有以下导入:

import play.api.libs.concurrent.AkkaGuiceSupport

我认为包含这个类的库是由sbt添加的,作为我在build.sbt中添加为libraryDependencies的库之一的依赖项。
然而,当我编译项目时,我得到:

$ sbt -java-home /usr/lib/jvm/java-8 -jvm-debug 9999 run
...
[info] Compiling 31 Scala sources and 1 Java source to /home/me/projects/my_project/target/scala-2.13/classes ...
[error] /home/me/projects/my_project/app/actors/MyService.scala:8:8: object AkkaGuiceSupport is not a member of package play.api.libs.concurrent
[error] import play.api.libs.concurrent.AkkaGuiceSupport
[error]        ^

在IntelliJ的项目外部库中,我可以看到:

"我错过了什么"

此编译错误的原因可能是什么?

........................................................

更新日期:
建置.sbt

name := "CH07"

version := "1.0"

lazy val `ch07` = (project in file(".")).enablePlugins(PlayScala)

scalaVersion := "2.13.4"

resolvers += "Spy Repository" at "http://files.couchbase.com/maven2"

libraryDependencies ++= Seq(
  jdbc,
  cacheApi,
  ws,
  "com.github.mumoshu" %% "play2-memcached-play28" % "0.11.0",
  "org.hsqldb" % "hsqldb" % "2.5.0",
  "org.jooq" % "jooq" % "3.14.4",
  "org.jooq" % "jooq-codegen-maven" % "3.14.4",
  "org.jooq" % "jooq-meta" % "3.14.4",
  "joda-time" % "joda-time" % "2.7",
  "com.ning" % "async-http-client" % "1.9.29",
  "com.github.scullxbones" %% "akka-persistence-mongo-common" % "3.0.5",
  "com.typesafe.akka" %% "akka-persistence" % "2.6.10",
  "com.typesafe.akka" %% "akka-persistence-query" % "2.6.10",
  "com.typesafe.akka" %% "akka-persistence-typed" % "2.6.10"
)

routesGenerator := InjectedRoutesGenerator

项目/插件.sbt

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.7")

项目/build.properties

sbt.version=1.3.10
dly7yett

dly7yett1#

首先,你可以看到它,因为它是play框架的一部分。你可以在PlayImport中看到更多的包,这些包不是你导入的,而是因为play而存在的。例如,如果你从libraryDependencies中删除jdbc,你可能会看到更多这样的错误(只是包名不同,而且只有在您实际使用它的情况下)。注意,您将能够在IntelliJ树中找到丢失的类,而编译器则不会。
在您的示例中缺少的导入是guiceAkkaGuiceSupportguice的一部分。请尝试将其添加到您的库依赖项中:

libraryDependencies ++= Seq(
  guice, // This is the missing part
  jdbc,
  cacheApi,
  ws,
  "com.github.mumoshu" %% "play2-memcached-play28" % "0.11.0",
  "org.hsqldb" % "hsqldb" % "2.5.0",
  "org.jooq" % "jooq" % "3.14.4",
  "org.jooq" % "jooq-codegen-maven" % "3.14.4",
  "org.jooq" % "jooq-meta" % "3.14.4",
  "joda-time" % "joda-time" % "2.7",
  "com.ning" % "async-http-client" % "1.9.29",
  "com.github.scullxbones" %% "akka-persistence-mongo-common" % "3.0.5",
  "com.typesafe.akka" %% "akka-persistence" % "2.6.10",
  "com.typesafe.akka" %% "akka-persistence-query" % "2.6.10",
  "com.typesafe.akka" %% "akka-persistence-typed" % "2.6.10"
)

相关问题