Step by Step load existing Play Project in IDEA

While setting up play with IDEA, it could be daunting to get things right in the first go itself. A step by step tutorial to help one out in setting up a development environment and trouble shooting issues while setting it up.

It starts off with having per-requisites on your OS. If you are looking out for a complete development environment bash script to wire up an environment you could look up earlier post, Bash Script for Play Development Environment

Once you have the Development Environment, we then proceed to load existing data sources as an IDEA project. We need to ensure before we move in that appropriate plug-ins are installed.

Pre-Requisites for IDEA

  • Add SBT Plugin: File->Settings->Plugins->Browse repositories-> SBT-> Install
  • Add Scala: File->Settings->Plugins->Browse repositories-> Scala->Install

sbtplugin


Checkout the project from the repository.

Navigate to the location where the sources would like to be cloned. On the bash issue the clone command to clone the repository.

git clone https://xxxxxx.xxxxxx.git

The command would clone the repository locally in the folder.

Load the Project

Open IDEA, Select option Import Project-> Open the Project Folder (datacaptive)-> open the folder by name Project (project) -> Select file build.sbt

Open the Project by pointing to build.sbt project file in the project folder.

In case the SDK is not selected following error is got, associate appropriate JDK by clicking “New” select JVM (located at /usr/lib/jvm/java-8-oracle)

jvmresolveerror

IDEA would start to resolve dependencies. It might take a little long to resolve for the first time.

resolvedependencies

After IDEA resolves the dependencies, it inquires to select the modules/data to include in the project

resolvingdependencyto

On resolving the project would be loaded, as shown below

screenshot-from-2016-11-25-12-05-48


Exceptional scenarios while loading the project

Controller Errors

Some time, the project would not load as anticipated. Following are some scenarios which were encountered and how they had been tackled.

If you encounter errors on Controllers, open up the sbt console in IDEA

SBT Console in IDEA

run clean and compile commands and issue a build for the project.

Create a Run Configuration as shown at the bottom of this post.

Run Successfuly


 

sbtrc client

Just in case On Resolving Dependencies, if there are errors “like unable to find sbtrc…”

 

...
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: com.typesafe.sbtrc#client-2-11;0.3.1: not found
[warn] :: com.typesafe.sbtrc#actor-client-2-11;0.3.1: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::

projects-> play-fork-run.sbt -> comment out

addSbtPlugin("com.typesafe.play" % "sbt-fork-run-plugin" % "2.5.9")

If I remove “sbt-fork-run-plugin” from that project, then it resolves the sbtrc dependencies.
https://github.com/gifman009/Licenta/blob/master/project/play-fork-run.sbt

I’m not sure if this is an Activator or SBT bug.


Unable to resolve symbol IDEA

When loading a project in IDEA, cannot resolve symbol with play framework occurs or play.data.validation does not exist

Solved it by "File" > "Open Project" and choose the base folder of the Play framework project (delete all idea settings file from the folder before so that it will reimport using the SBT settings).

http://stackoverflow.com/questions/21577573/intellij-idea-can-not-resolve-symbol-with-play-framework


Source Folder not loaded

The above steps at times would not reflect the Project Source files. In such  a case,

  1. closed IntelliJ,
  2. deleted the .idea folder or stash it
  3. restarted IntelliJ and opened the same project.

IntelliJ will generate the new .idea folder and the folders will appear.


Run Configuration

  1. Create a new Run Configuration – From the main menu, select Run -> Edit Configurations
  2. Click on the + to add a new configuration
  3. From the list of configurations, choose “SBT Task”
  4. In the “tasks” input box, simply put “run”
  5. Apply changes and select OK.
  6. Now you can choose “Run” from the main Run menu and run your application

data captive run configuration