Sunday, February 19, 2012

Neo4J with Scala Play! 2.0 on Heroku (Part 3) :: Play 2.0/Idea

Play!2.0 Scala and Idea CI

This post is a continuation of this post, where I’ve introduced Neo4J and how to install it. But it requires that you already followed this post.


Event if the ScalaIDE 2.0 has just been released. I still prefer Intellij for editing Scala, because even it's community edition has a powerful and polish Scala support (after having installed the plugin...).
And while, playing with the 2.0 version of Play! you'll enjoy the use of CoffeeScript to heal your JS head aches, you'll also loved the CoffeeBrew plugin.
Here the goal is to help you create a Play! 2.0 RC1 scala project, update the sbt configuration for sbt-idea, and finally generate the IDEA module.
Having done such easy tasks, you'll have the full IDEA powerfull in your hands.

Create the project

First of all, we need to create the project for what we'll try to do (using Neo4J through it's REST API).
For that, you should have the play executable in your PATH setup, and able to run the following in console.
play new Play20WithNeo4J Which will prompt you some questions, that you'll answer the following (no color question, don't worry but a little remark later if you're using Windows ^^):
What is the application name? >
Which template do you want to use for this new application?
1 - Create a simple Scala application
2 - Create a simple Java application
3 - Create an empty project
> 1
OK, application Play20WithNeo4J is created.
Have fun!
Basically, it asks you the name of your app, and it's language (note that we've chosen the scala way).

Setting sbt-idea

Play! in the new 2.0 version is using sbt to configure the project and run tasks (such as deploy start/run and so on). The sbt version in used is the 0.11.2 at the time writing, and is embedded with the install.
So that, you can already launch the sbt console by either run play or play console to have all Play! deps on classpath.
Before running any command, let's modify some sbt conf files to have sbt-idea being able to create an IDEA module for our project.
Play 2.0 comes with a default configuration for sbt, so that, those files are already present under the project folder:
  • Build.scala : contains the app information
  • : contains the sbt version 
  • plugins.sbt : contains default resolver and play 2.0 RC1 Snapshot deps
Starting from there three actions are required in order to import sbt-idea.
Create build.sbt
We have to create a new file name built.sbt in which you'll add the TypeSafe (Scala company) as a searchable repository.
resolvers += Classpaths.typesafeResolver
Update the plugins.sbt
Add the needed reference to the plugin sbt-idea and add it to the plugin list of sbt.
resolvers ++= Seq(
    Resolver.url("Play", url(""))(Resolver.ivyStylePatterns),
    "Typesafe Repository" at ""

addSbtPlugin("play" % "sbt-plugin" % "2.0-RC1-SNAPSHOT")

resolvers += "sbt-idea-repo" at ""

addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "0.11.1-SNAPSHOT")

libraryDependencies += "play" %% "play" % "2.0-RC1-SNAPSHOT"
Update the Build.scala
Add the sbt-idea plugin repository in the resolvers' list.
import sbt._
import Keys._
import PlayProject._

object ApplicationBuild extends Build {

  val appName = "playbasket"
  val appVersion = "1.0"

  val sbtIdeaRepo = "sbt-idea-repo" at ""

  val appDependencies = Seq(

  val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
    // Add your own project settings here
    resolvers ++= Seq(


Create IDEA module

Now everything is quite simple. Get back to the project root and use play. When entered the console, the module will be build by simply running idea.
Having the iml created, all you have to do is to open Idea, create a project and import the module file right after.
Note, if you're encountering problem with the scala environment (that happens at first time). You'll have to create another module (short-lived), then add it the Scala facet where you'll be able to configure the Scala compiler.
When done, you can delete the module, and getting back to the original, you'll be able now to refer to the Scala compiler/libraries.

Let's move to Json and Play