【问题标题】:Successfully compile a sub-project (admin area) in Play (framework)在 Play(框架)中成功编译一个子项目(管理区)
【发布时间】:2017-10-25 21:10:43
【问题描述】:

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

[错误] ...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

ma​​in-project/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"

ma​​in-project/modules/admin/build.sbt

name := "admin"

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

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

       # home page
       GET     /                   controllers.HomeController.index

       ->  /admin admin.Routes

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

ma​​in-project/modules/admin/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 是一头精致的野兽;容易受到大量配置和兼容性问题的影响 - 所以我不觉得我自己在磨练答案。谁能看到我看不到的东西?谢谢

【问题讨论】:

    标签: playframework routes sbt subproject


    【解决方案1】:

    在您的主项目/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)
    

    【讨论】:

    • 这是一个好地方,但它并没有清除错误。还有什么用新鲜的眼睛看起来不合适的地方吗?
    • 我认为您在主 sbt 中缺少根项目的 dependsOn 和 aggregateOn。
    猜你喜欢
    • 1970-01-01
    • 2011-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多