【发布时间】:2017-12-30 08:58:03
【问题描述】:
我有一个带有播放模块和其他 scala 模块的多模块播放应用程序,并且一切正常。我想添加一个自定义 Twirl 模板,这就是问题出现的时候。这是Multiproject structure
build.sbt:
name := """scalaplay"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala).dependsOn(restfulapi,util).aggregate(restfulapi,util)
scalaVersion := "2.11.7"
/**
* .dependsOn(util). will let us use element from dbmodule into apirestmodule. Specifically some element and structure
* of the data model.
*
*/
lazy val restfulapi = (project in file("modules/apirest")).enablePlugins(PlayScala).dependsOn(util).settings(scalaVersion:="2.11.7",
libraryDependencies ++= Seq(
cache,
"org.scalatestplus.play" %% "scalatestplus-play" % "1.5.1" % Test
)
)
lazy val util = (project in file("modules/dbmodule")).settings(scalaVersion:="2.11.7")
TwirlKeys.templateFormats += ("csv" -> "views.CsvFormat")
apirest.routes 的一部分:
#processing premierLeague
POST /premier/match controllers.PremierleagueController.insertMatch
GET /premier/matchs controllers.PremierleagueController.getMatchGame
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
GET /records controllers.HomeController.records
使用模板的动作在 HomeController.scala 中:
......
def records = Action {
Ok(views.csv.records(Record.sampleRecords))
}
.....
这是我显示来源时的结果:
[scalaplay] $ show twirlCompileTemplates::sourceDirectories
[info] restfulapi/compile:twirlCompileTemplates::sourceDirectories
[info] List(/Users/ldipotet/scala/scalaplay/modules/apirest/app)
[info] root/compile:twirlCompileTemplates::sourceDirectories
[info] List(/Users/ldipotet/scala/scalaplay/app)
这是我尝试编译项目时的编译错误:
[info] Compiling 22 Scala sources and 1 Java source to /Users/ldipotet/scala/scalaplay/modules/apirest/target/scala-2.11/classes...
[error] /Users/ldipotet/scala/scalaplay/modules/apirest/app/controllers/HomeController.scala:72: object csv is not a member of package views
[error] Ok(views.csv.records(Record.sampleRecords))
[error] ^
[error] one error found
[error] (restfulapi/compile:compileIncremental) Compilation failed
[error] Total time: 6 s, completed 24-jul-2017 17:18:11
有关更多信息,相同的自定义模板在单个 playframework 项目中编译和工作
【问题讨论】:
标签: scala templates playframework multi-module