playframework Setting up your preferred IDE IntelliJ IDEA


Example

Prerequisites

  1. Intellij IDEA installed (Community or Ultimate edition)
  2. Scala Plugin installed in IntelliJ
  3. A standard Play project, created for instance with Activator (activator new [nameoftheproject] play-scala).

Opening the project

  1. Open IntelliJ IDEA
  2. Go to menu File > Open ... > click the whole folder [nameoftheproject] > OK
  3. A popup opens with a few options. The default values are good enough in most cases, and if you don't like them you can change them somewhere else later. Click OK
  4. Intellij IDEA will think a bit, then propose another popup to select which modules to select in the project. There should be two modules root and root-build selected by default. Don't change anything and click OK.
  5. IntelliJ will open the project. You can start viewing the files while IntelliJ keep thinking a bit as you should see in the status bar in the bottom, then it should finally be fully ready.

Running the applications from Intellij

From there some people use the IDE just to view/edit the project, while using the sbt command line to compile/run/launch tests. Others prefer to launch those from within Intellij. It is required if you want to use the debug mode. Steps :

  1. Menu Run > Edit configurations...
  2. In the popup, click the + in the top left > Choose Play 2 App in the list
  3. Name the configuration, for instance [nameofyourproject]. Leave the default options and hit OK.
  4. From the Run menu, or the buttons in the UI, you can now Run or Debug using this configuration. Run will just launch the app, as if you did sbt run from the command line. Debug will do the same thing but allow you to place breakpoints in the code to interrupt the execution and analyze what's happening.

Auto-import option

This is an option global to the project, that is available at creation time and afterwards can be changed in the menu Intellij IDEA > Preferences > Build, Execution, Deployment > Build tools > SBT > Project-level settings > Use auto-import.

This option has nothing to do with the import statements in the Scala code. It dictates what Intellij IDEA should do when you edit the build.sbt file. If auto-import is activated, Intellij IDEA will parse the new build file immediately and refresh the project configuration automatically. It gets annoying quickly as this operation is expensive and tends to slow Intellij when you're still working on the build file. When auto-import is desactivated, you have to indicate manually to Intellij that you edited the build.sbt and would like the project configuration to be refreshed. In most cases a temporary popup will appear to ask you if you would like to do so. Otherwise go to the SBT panel in the UI, and click the blue circling arrows sign to force the refresh.