Sunday, June 15, 2014

Module Naming Conventions for Play 2.2 and IntelliJ 13.1

So today I noticed something strange with +IntelliJ IDEA and the +Play Framework 's build.sbt file.

Say you create a project using the following method:


1. Create a new app using the play new command (testapp)
2. Naming the application (Test_Application)
3. Selecting the Simple Java application template

When you open the project with IntelliJ and look at the build.sbt file, this is what you see:


This means that the project ins't properly resolving within IntelliJ. This can lead to false error flags and almost zero code assist support when building your controllers and whatnot. Now your Play application will still run as normal, but at this point you might as well use Notepad to do your code editing - IntelliJ will be almost useless to you.

The fix, however is simple. Simply rename the project's build module to the same name as the main project module and attach "-build" to the end of it. This can be achieved by going to File > Project structure... > Modules. Mine show up like this;


From here what I will do is change the build module's name to "testapp-build", 



click OK and when I look at my build.sbt file again, everything should resolve properly and my code assist should work splendidly:


Well, it's almost fixed. Restructure the file as follows to make sure the library dependencies resolve properly as well:


To avoid all this tra-la-la, I would advise skipping the step to name your application when creating the application from the command line. 

Happy coding!

Bug affects:
Play 2.2.3
IntelliJ 13.1.3 Build IU-135.909
Play plugin 0.38.437


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