Tuesday, June 03, 2014

Proper build.sbt Settings for Play 2.2 and IntelliJ

I came across a bug today that cause IntelliJ 13.1 to act strangely when passing Java objects to Scala templates.










For example the snippet:
public static Result login() {
 ok(login.render(Form.form(Login.class)));
}

will compile and run, but IntelliJ will flag it as an error because it says that it found a play.data.Form object when the Scala template was expecting a play.api.data.Form object. Now that's just the tip of the iceberg, I even found that in some cases my routes (for redirects within the controller) were flagged as unresolvable objects.

Fear not, for the solution is simple. Your build.sbt file will look like this when Play generates the project:
name := "testapp"

version := "1.0-SNAPSHOT"

libraryDependencies ++= Seq(
  javaJdbc,
  javaEbean,
  cache
)  

play.Project.playJavaSettings

Simply change it as follows:

import play.Project._

name := "testapp2"

version := "1.0-SNAPSHOT"

libraryDependencies ++= Seq(
  javaJdbc,
  javaEbean,
  cache
)     

playJavaSettings

Run the following commands:
play clean
play compile

And voila! Those nasty red squiggly lines are gone.

Bug notes


This bug was present in the following software and their versions:

IntelliJ IDEA version: 13.1 IU-135.475
Play Framework version: 2.2.1 - 2.2.3
Play 2.0 plugin version: 0.33.404
Scala plugin version: 0.33.403

No comments: