Are you working in a limited environment? You cannot choose your build system ? Or maybe you are a fan of maven? Even so, you still want to build an application in Scala with Play Framework 2? This article is for YOU.
Let’s begin by defining a very simple pom.xml.
First, let’s add Scala :
Then I’ll add sbt to maven :
Yes, this plugin will ask maven to run SBT. We need this as play cannot work without SBT plugins.
Next is play himself :
The play plugin adds maven goals to execute play commands.
> mvn clean play2:run
[INFO] Scanning for projects…
…
[INFO] — — play2-maven-plugin:1.0.0-rc5:run (default-cli) @ project-application_2.12 — -
— — (Running the application, auto-reloading is enabled) — -
[info] p.c.s.AkkaHttpServer — Listening for HTTP on /0:0:0:0:0:0:0:0:9000
[INFO] (Server started, use [Enter] to stop…)
As with SBT, the incremental compilation is on by default. A first HTTP request is also needed to really execute the compilation. And that’s all folks, the play application now runs in dev mode.
What about building the application?
mvn clean package play2:dist
Just with that, you now have a full working play application build with maven.
Notes :
— Sadly, you cannot change routes defaults imports. Meaning you will most likely have unused imports and need to remove the-X-fatal-warnings
compiler flag.
— If you use twirl templates, here is the required plugin :