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.
What I found so fa
Play 2.2 supports sbt 0.13 so to use it for your expected project layout I'd recommend to have the following build.sbt
in the my_project
root 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)
Since my_project
uses Play 2.2 class - 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")
That might explain why Play module is usually a top-level one (since so much is needed in the top-level project that it effectively becomes a Play module).
The complete project layout is as follows:
$ tree
.
├── build.sbt
└── project
├── build.properties
└── plugins.sbt
1 directory, 3 files
What's quite interesting is that even without all the project directories and no Play project in place (just a definition in the build.sbt
) you can still run
the web_ui
project and access it with your web browser (!) It will fail for obvious reasons, but shows there's not much needed to get running with sbt and 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)