I've been working with Play2 Framework for several years now and it's a very nice way to develop in Scala. Some of the Play projects have grown rather large and have become sluggish in combination with SBT. Resolving dependencies, compiling and starting Play all take a long time with SBT. Perhaps my biggest objection is that SBT can not stage a self-contained integration-test environment. These shortcomings have forced me to look at SBT alternatives. I arrived at a way to build and run Play projects with support for auto-reloading using Maven, play2-maven-plugin, sbt-compiler-maven-plugin, Eclipse, DCEVM and Zinc. This article describes how to set up such an environment for your own enjoyment.
Start by downloading the following tools:
- Java SE Development Kit 7u51 - needs registration at Oracle (which is unfortunate but free)
- DCEVM (full) for Java 7u51 (build 3) - make sure to get the full version and not the light version
- Scala IDE for Eclipse - I used version Scala IDE 4.0.0 and Eclipse 4.4 Luna
- Zinc latest version - I used Zinc 0.3.7
- Apache Maven latest version - I used Maven 3.2.3
Which version of Scala IDE, Eclipse, Zinc or Maven you install should not matter much. However, the Java and DCEVM versions do matter. It is paramount that the build versions of both Java and DCEVM (in this case 7u51) match perfectly and that you get a full version of DCEVM.
$ sudo java -jar installer-full-jdk7u51.3.jar
Make sure that Java 7u51 is your default Java version. You can verify this by running `java -version` from the command line. Also make sure DCEVM is correctly patched into the JVM as an alternative JVM, which can be verified by running `java -XXaltjvm=dcevm -version`, which should show something like:
$ java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
$ java -XXaltjvm=dcevm -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Dynamic Code Evolution 64-Bit Server VM (build 24.51-b03-dcevmfull-3, mixed mode)
$ ./bin/zinc -start
Nailgun server running with 0 cached compilers
Version = 0.3.7
Zinc compiler cache limit = 5
Resident scalac cache limit = 0
Analysis cache limit = 5
$ git clone https://github.com/webdevelopersdiary/play2-maven-plugin
$ cd play2-maven-plugin/plugin
$ mvn compile install
$ mvn -P hotreload compile play2:run
I imagine this will also work with other IDEs that have hotswapping support, like Netbrains IntelliJ IDEA, but I have not tried others so far. If you have tried, please drop your experience in the comments below. Grzegorz Slowikowski, the author of play2-maven-plugin, has brought to my attention that LinkedIn is planning to bring hot-reload support for Play 2 to Gradle. Somewhere in the future the play2-maven-plugin will support hot-reloading natively as well, until that time it will remain in beta. Simpler and more portable alternatives to SBT are on the way, stay tuned. Thanks for reading.