A generic, multi-module, Play Framework Scala project template, with some basic configuration and helpers.
Replace every instance of com.example
with your company/organization's domain, and myapp
with the name of your application.
myapp-core
– A vanilla Scala/Java module. This is where most of your code should live.myapp-play
– The Play Framework module. This should be a thin layer of controllers and other web server logic on-top ofmyapp-core
. Making this module as light as possible should make it easier to move to a different app server in the future, should you want to.myapp-test
– Testing code module that's only included intest
scope. This isn't not where your tests should live, only testing helpers/utilities to be used and shared between thecore
andplay
modules' tests.
project/Build.scala
– Module configurationproject/BuildSettings.scala
– Generic and plugin settings for each moduleproject/Dependencies.scala
– Dependency configuration, pre-configured with some convenient dependencies
-
The
core
module definesHttpRuntimeException
. This implementation ofRuntimeException
adds Http status code to an exception, making it explicit which status code should be returned to the client when this exception is thrown. Make your business exceptions inherit from this base exception, so you'll have meaningful exceptions with the right status codes. (seeGlobal
notes.) -
The
Global
object in theplay
modules allows you to intercept errors/exceptions and handle them with a custom error page. This code is commented out so you'll get the default Play error page which is useful during development. Uncomment and create your own error page before running in production. -
Global
also uses the aforementionedHttpRuntimeException
to send the correct status code. -
Logging is configured in the
conf/application-logger.xml
logback config file. -
The top level
root
project aggregates all modules, so any action you run on it (compile
,test
, etc.) will be performed for all projects. If you want to runplay
specific tasks/commands (such as:run
,start
, etc.), you'll need to enter theplay
project and run it then:
$ cd ./play-template
$ sbt
sbt> compile # aggregated on all projects
sbt> project myapp-play # enter play module
sbt> run # play-specific command
To return to the root project: sbt> project root
.