需要有关Play 2.2子模块以及其他模块作为依赖项的项目布局的建议 [英] Need advice on project layout for Play 2.2 submodule with other modules as dependencies

查看:91
本文介绍了需要有关Play 2.2子模块以及其他模块作为依赖项的项目布局的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an existing SBT project with modules. I want to add Play 2.2 into my project as a submodule. This new Play module will depend on other modules.

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

What I found so far was mostly about Play being the main project with supporting modules. If Play does support this setup, please point me in the right direction how to do it. Thanks.

我想要的设置(简化):

My intended setup (simplified):

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

推荐答案

两个选项:

1)有一个空"主项目,汇总了您的3个子项目:

1) have an 'empty' main project aggregating your 3 sub-projects:

root
\--- project
    \--- Build.scala
\--- web_ui
\--- common
\--- desktop_ui

在Build.scala中,如下所示:

And in Build.scala something like this:

lazy val common = Project(id = "common", base = file("common"))
lazy val desktopUi = Project(id = "desktop_ui", base = file("desktop_ui")
lazy val webUi = play.Project(name = "web_ui", path = file("web_ui"))
.dependsOn(common, desktopUi)

懒惰的val root = Project(id ="root",base = file(.")).aggregate(common,desktopUi,webUi)

lazy val root = Project(id = "root", base = file(".")).aggregate(common, desktopUi, webUi)

使用此选项,您可以从根文件夹启动sbt并构建所有项目.您还可以在此唯一的构建定义中定义所有设置和依赖性.

With this option, you can start sbt from the root folder and build all your projects. You also define all the settings, dependencies in this unique build definition.

2)可以使用另一种布局来使子项目彼此独立.我倾向于采用这种方式,因为它比较干净(例如,我可以将common作为一个独立的项目而不是作为一个子模块来进行工作),但构建整个系统并不方便.

2) Another layout can be used to keep your sub-projects independent from each other. I tend to prefer this way because it's cleaner (e.g. I can work on common as an independent project, not as a submodule) but it is not as convenient to build the whole system.

root
\--- web_ui
    \--- project
        \--- Build.scala
\--- common
     \--- project
        \--- Build.scala
\--- desktop_ui
     \--- project
        \--- Build.scala

这里,每个项目都是独立的(如果需要,您可以使用build.sbt而不是Build.scala,请参见sbt文档)以及在web_ui/project/Build.scala中:

Here, each project is independent (you can use build.sbt instead of Build.scala if you want, see sbt documentation) and in web_ui/project/Build.scala :

lazy val common = RootProject(file("../common"))
lazy val desktopUi = RootProject(file("../desktop_ui"))

val main = play.Project(name = "web_ui", path = file("web_ui")).dependsOn(common, desktopUi) 

在这里,root仅用于将所有内容收集到一个文件夹中,然后play项目引用其他模块.

Here, root is just used to gather everything in one folder, then the play project references the other modules.

这篇关于需要有关Play 2.2子模块以及其他模块作为依赖项的项目布局的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆