我一直试图将我的Play项目分成模块。我关注this example BuildSettings.scala build file。它进展顺利 - 所有编译完毕,我都有工作测试。
在我重写了主项目中的一个控制器以使用模块中的服务后,我开始遇到大量错误。
Play似乎无法找到一些依赖项。我收到此错误
object ws is not a member of package play.api.libs
import play.api.libs.ws.WS
当我转到该文件时,它可以找到play.libs.WS
,但不能找到play.api.libs.ws.WS
。
我的 Build.scala 如下:
val srcMain = Seq(
scalaSource in Compile <<= (sourceDirectory in Compile)(identity),
javaSource in Compile <<= (sourceDirectory in Compile)(identity),
resourceDirectory in Compile <<= (sourceDirectory / "conf")(identity),
scalaSource in Test <<= (sourceDirectory in Test)(identity),
parallelExecution in Test := false
)
lazy val modules = Seq(mod)
def projectToRef(p: Project): ProjectReference = LocalProject(p.id)
lazy val moduleRefs = modules map projectToRef
lazy val mod = Project("mod", file("modules/mod"), settings = buildSettings ++ srcMain)
.settings(
libraryDependencies ++= Seq(
/* Some dependencies */
)
)
lazy val main = play.Project(appName, appVersion, appDependencies, settings = Resolvers.all)
.dependsOn(api)
lazy val api = Project("api", file("modules/api"), settings = buildSettings ++ srcMain).settings(
libraryDependencies ++= Seq(
cache, apache
)
) aggregate (moduleRefs: _*)
override def rootProject = Some(main)
project / plugins.sbt 看起来像这样
// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
resolvers += "Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
// Use the Play sbt plugin for Play projects
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.3" exclude("org.apache.commons", "commons-lang3"))
addSbtPlugin("com.typesafe.sbt" % "sbt-atmos-play" % "0.3.2")
答案 0 :(得分:0)
您的project/build.scala
看起来真的如下:
val mainSettings = Seq(
scalaSource in Compile := sourceDirectory in Compile,
javaSource in Compile := sourceDirectory in Compile,
resourceDirectory in Compile := sourceDirectory / "conf",
scalaSource in Test := sourceDirectory in Test,
parallelExecution in Test := false
)
lazy val mod = (project in file("modules/mod")).settings(buildSettings ++ mainSettings: _*).settings(
libraryDependencies ++= Seq(
/* Some dependencies */
)
)
lazy val main = play.Project(appName, appVersion, appDependencies, settings = Resolvers.all)
.dependsOn(api)
lazy val api = (project in file("modules/api")).settings(buildSettings ++ mainSettings: _*).settings(
libraryDependencies ++= Seq(
cache, apache
)
) aggregate mod
override def rootProject = Some(main)
我不明白为什么你要在mainSettings
进行重新分配?你能分享mainSettings
背后的想法吗?您如何看待play.api.libs.ws.WS
来到您的项目?谁带来了?您不应该将ws
播放模块添加到main
或api
作为依赖项吗?