sbt - 需要有关 Play 2.2 子模块的项目布局的建议,其他模块作为依赖项

标签 sbt playframework-2.2

我有一个带有模块的现有 SBT 项目。我想将 Play 2.2 作为子模块添加到我的项目中。这个新的 Play 模块将依赖于其他模块。

到目前为止,我发现的主要是 Play 是带有支持模块的主要项目。如果 Play 确实支持此设置,请指出正确的方向。谢谢。

我的预期设置(简化):

my_project
\--- desktop_ui
     \--- src/main
     \--- src/test
\--- common
     \--- src/main
     \--- src/test
\--- web_ui (Play framework)
     \--- app/controllers
     \--- app/views
     \--- app/models
     \--- conf

最佳答案

Play 2.2 supports sbt 0.13所以要将它用于您预期的项目布局,我建议使用以下 build.sbtmy_project根项目:

import play.Project._

lazy val my_project = project in file(".") aggregate (desktop_ui, common, web_ui)

lazy val desktop_ui = project dependsOn common

lazy val common = project

// no need to dependsOn "common" since it's already a dependency of "desktop_ui"
lazy val web_ui = play.Project(name = "web_ui", path = file("web_ui"))
                    .dependsOn(desktop_ui)

由于my_project使用 Play 2.2 类 - play.Project - 定义一个 Play 项目,project/plugins.sbt是必须的。
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.2-RC1")

这或许可以解释为什么 Play 模块通常是顶级模块(因为顶级项目中需要的东西太多以至于它实际上成为了 Play 模块)。

完整的项目布局如下:
$ tree
.
├── build.sbt
└── project
    ├── build.properties
    └── plugins.sbt

1 directory, 3 files

有趣的是,即使没有所有项目目录,也没有 Play 项目(只是 build.sbt 中的一个定义),您仍然可以 run web_ui项目并使用您的网络浏览器访问它(!)它会由于明显的原因而失败,但表明使用 sbt 和 Play 运行并不需要太多。
$ sbt
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Loading project definition from /Users/jacek/sandbox/so/play-2.2-multi/my_project/project
[info] Updating {file:/Users/jacek/sandbox/so/play-2.2-multi/my_project/project/}my_project-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Set current project to my_project (in build file:/Users/jacek/sandbox/so/play-2.2-multi/my_project/)
[my_project]> projects
[info] In file:/Users/jacek/sandbox/so/play-2.2-multi/my_project/
[info]     common
[info]     desktop_ui
[info]   * my_project
[info]     web_ui
[my_project]> project web_ui
[info] Set current project to web_ui (in build file:/Users/jacek/sandbox/so/play-2.2-multi/my_project/)
[web_ui]> run
[info] Updating {file:/Users/jacek/sandbox/so/play-2.2-multi/my_project/}common...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Updating {file:/Users/jacek/sandbox/so/play-2.2-multi/my_project/}desktop_ui...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Updating {file:/Users/jacek/sandbox/so/play-2.2-multi/my_project/}web_ui...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.

--- (Running the application from SBT, auto-reloading is enabled) ---

[info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9000

(Server started, use Ctrl+D to stop and go back to the console...)

[info] play - Application started (Dev)

关于sbt - 需要有关 Play 2.2 子模块的项目布局的建议,其他模块作为依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20925291/

相关文章:

scala - Sbt 多模块构建 - 维护模块 dep 图作为模块中的 libraryDependencies

scala - 播放框架 : JDBC driver class disappears after reload

java - 如何在 Play Framework 2.2 中自定义 unmanagedResourceDirectories 和 exceptFilter?

scala - Play Framework 路由和scala predef值

java - 玩2.2 不带插件启动DefaultApplication

sbt - 为什么Play应用程序无法解析Docker容器内部的依赖关系?

scala - SBT 任务将 debian 文件复制到其他文件夹

java - Play 2.1.1 构建依赖

scala - 尝试从 Artifactory 虚拟存储库下载时,SBT 无法找到凭据

jenkins - Jenkins依赖sbt依赖吗?