SBT 0.13.8 多模块项目与 Playframework 2.4.2

SBT 0.13.8 multi module project with Playframework 2.4.2

我有一个包含两个子模块的简单项目,proja 和 projb。 Proja 包含在 projb 中的 UserControllerImpl 中使用的特征 UserController。

github 上的项目:https://github.com/aswarcewicz/play-sbt-multimodule

root build.sbt:

name := """proj"""

version := "1.0-SNAPSHOT"

lazy val proja = Project(id = "proj-a", base = file("modules/proj-a"))
  .enablePlugins(PlayScala)

lazy val projb = Project(id = "proj-b", base = file("modules/proj-b"))
  .enablePlugins(PlayScala)
  .dependsOn(proja)
  .aggregate(proja)

lazy val root = Project(id = "proj", base = file("."))
  .enablePlugins(PlayScala)
  .dependsOn(proja, projb)
  .aggregate(proja, projb)

scalaVersion := "2.11.6"

libraryDependencies ++= Seq(
)

// Play provides two styles of routers, one expects its actions to be injected, the
// other, legacy style, accesses its actions statically.
routesGenerator := InjectedRoutesGenerator

编译器错误:

modules/proj-b/app/controllers/UserControllerImpl.scala:5: not found: object controller [error] import controller._

/modules/proj-b/app/controllers/UserControllerImpl.scala:10: not found: type UserController [error] class UserControllerImpl extends Controller with UserController {

我不知道哪里出了问题。

您应该将 SBT 文件更改为:

name := """proj"""

version := "1.0-SNAPSHOT"

lazy val root = Project(id = "proj", base = file("."))
  .enablePlugins(PlayScala)
  .aggregate(proja, projb)

lazy val proja = Project(id = "proj-a", base = file("modules/proj-a"))
  .enablePlugins(PlayScala)

lazy val projb = Project(id = "proj-b", base = file("modules/proj-b"))
  .enablePlugins(PlayScala)
  .dependsOn(proja)

scalaVersion := "2.11.6"

libraryDependencies ++= Seq(
)

// Play provides two styles of routers, one expects its actions to be injected, the
// other, legacy style, accesses its actions statically.
routesGenerator := InjectedRoutesGenerator

添加正确的依赖项并重新加载您的项目。

您有一些错误。

我将提交您的项目需要在以下存储库中工作的更改。 https://github.com/martinscmb/play-sbt-multimodule

localhost:9000/test output:
{"user":{"name":"toto","age":25,"email":"toto@jmail.com","isAlive":true,"friend":{"name":"tata","age":20,"email":"tata@coldmail.com"}}}

您想定义一个 commonSettings 模块并遍历所有地方:

import sbt.Keys._

lazy val commonSettings = Seq(
  scalaVersion := "2.11.7",
  routesGenerator := InjectedRoutesGenerator,
  version := "1.0-SNAPSHOT"
)

lazy val root = (project in file("."))
    .enablePlugins(PlayScala)
    .settings(commonSettings)
    .settings(Seq(name := """proj"""))
    .dependsOn(`proj-a`, `proj-b`)
    .aggregate(`proj-a`, `proj-b`)

lazy val `proj-b` = (project in file("modules/proj-b"))
  .enablePlugins(PlayScala)
  .settings(commonSettings)
  .dependsOn(`proj-a`).aggregate(`proj-a`)

lazy val `proj-a` = (project in file("modules/proj-a"))
  .enablePlugins(PlayScala)
  .settings(commonSettings)