Need consultation on the project layout for submodule 2.2 to play with other modules as dependencies

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

What I have found so far has mainly been that Play is the main project with supporting modules. If Play supports this setting, please point me in the right direction on how to do this. Thanks.

My supposed 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 
+7
source share
2 answers

Two options:

1) have an “empty” main project uniting your 3 subprojects:

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

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) 

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

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

2) Another layout can be used to make your subprojects independent of each other. I prefer this method because it is cleaner (for example, I can work on common as an independent project, and not as a submodule), but it is not so convenient to build the whole system.

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

Here, each project is independent (you can use build.sbt instead of Build.scala, if you want, see the 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) 

Here root is used only for collecting in only one folder, then the playback project refers to other modules.

+3
source share

Play 2.2 supports sbt 0.13 , therefore, to use it for the expected layout of the project, I would recommend having the following build.sbt in my_project project root:

 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 already a dependency of "desktop_ui" lazy val web_ui = play.Project(name = "web_ui", path = file("web_ui")) .dependsOn(desktop_ui) 

Since my_project uses play class 2.2 - play.Project - to define a play project, project/plugins.sbt is required.

 resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/" addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.2-RC1") 

This may explain why the Play module is usually high-level (since a high-level project requires a lot to become a Play module).

The full layout of the project is as follows:

 $ tree . ├── build.sbt └── project ├── build.properties └── plugins.sbt 1 directory, 3 files 

Interestingly, even without all the project directories and without the Play project (only the definition in build.sbt ), you can still run the web_ui project and access it in your web browser (!) For obvious reasons, it will fail, but it shows that to work with sbt and Play is not so necessary.

 $ 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) 
+4
source share

All Articles