在Play(框架)中成功编译子项目(管理区域)

时间:2017-10-25 21:10:43

标签: playframework routes sbt subproject

我想在 Play Framework (2.6)中将管理区域设置为子项目,所以一直使用this documentation但即将到来编译错误,我无法修复:

  

[error] ... conf \ routes:15:not found:value admin

     

[错误] - > / admin admin.Routes

这是我的项目结构

   main-project
   _build.sbt
   _app
     _controllers
     _models
     _views
   _conf
     _application.conf
     _routes
   _modules
     _admin
       _build.sbt
       _app
         _controllers
         _models
         _views
       _conf
         _admin.routes
   _project
     _build.properties
     _plugins.sbt

主要项目/ build.sbt

   import play.sbt.routes.RoutesKeys

   name := "main-project"

   val defaultResolvers = Seq(
     Resolver.sonatypeRepo("snapshots")
   )

   lazy val commonSettings = Seq(
     organization := "com.boardrs",
     version := "1.0-SNAPSHOT",
     scalaVersion := "2.12.2",
     scalacOptions ++= Seq("-feature", "-language:postfixOps"),
     resolvers ++= defaultResolvers
   )


   lazy val admin = (project in file("modules/admin"))
     .settings(
       commonSettings
     ).enablePlugins(PlayScala)

   lazy val root = (project in file("."))
     .settings(
       commonSettings
     )
     .enablePlugins(PlayScala)


   routesGenerator := InjectedRoutesGenerator
   RoutesKeys.routesImport += "play.modules.reactivemongo.PathBindables._"

   libraryDependencies += guice
   libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "3.0.0" % Test
   libraryDependencies += "com.h2database" % "h2" % "1.4.194"
   libraryDependencies += "com.typesafe.play" %% "play-json" % "2.6.0"
   libraryDependencies += ws

   // Play 2.6.x
   libraryDependencies ++= Seq(
     "org.reactivemongo" %% "play2-reactivemongo" % "0.12.5-play26"
   )


   libraryDependencies += "org.webjars" % "bootstrap" % "3.1.1-2"

主要项目/模块/管理/ build.sbt

name := "admin"

PlayKeys.devSettings += "play.http.router" -> "admin.Routes"

main-project / conf / routes (包含错误中引用的行的文件)

       # home page
       GET     /                   controllers.HomeController.index

       ->  /admin admin.Routes

       GET     /assets/*file       controllers.Assets.at(path="/public", file)

主要项目/模块/管理/ CONF / admin.routes

   GET /index                  controllers.admin.HomeController.index()

   GET /assets/*file           controllers.admin.Assets.versioned(path="/public/lib/admin", file)

我仔细查看过(在Stack Overflow上)和其他地方的解决方案,例如this question非常相似,但答案包含了已被弃用的技​​术。我尝试了多种组合,但Play Framework是一个微妙的野兽;容易受到大量配置和兼容性问题的影响 - 所以我觉得我并不觉得自己正在研究答案。任何人都能看到我不能做的事吗?感谢

1 个答案:

答案 0 :(得分:0)

在你的main-project / build.sbt中:

尝试更改:

lazy val admin = (project in file("admin"))

lazy val admin = (project in file("modules/admin"))

我认为您错过了主要sbt中根项目的dependsOn和aggregateOn。

尝试更改:

lazy val root = (project in file("."))
 .settings(
   commonSettings
 )
 .enablePlugins(PlayScala)

lazy val root = (project in file("."))
 .settings(
   commonSettings
 )
 .enablePlugins(PlayScala).dependsOn(admin).aggregate(admin)