Project无法访问Play多模块项目中的依赖项?

时间:2014-05-13 17:18:55

标签: playframework sbt playframework-2.2

我一直试图将我的Pl​​ay项目分成模块。我关注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")

1 个答案:

答案 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播放模块添加到mainapi作为依赖项吗?