Update: In newer versions if IntelliJ IDEA, it is no longer necessary to create the module from play/activator. IntelliJ IDEA has now a really good support for SBT projects. If exists, delete all the idea related directories inside your project. Then in IntelliJ IDEA click File -> Open and choose your build.sbt file. That's all.
IntelliJ IDEA has a good integration for the Play Framework 2. Sometimes it jams, but most of the time it runs. I use it to run(single, all) tests, start or debug the play application and edit my code (o; And this all from within the IDE and without the sbt console.
Here is a short tutorial with the most important steps. Currently I use IntelliJ IDEA 12.1 with the newest Play Framework 2 and Scala plugins.
1. Create a new application
play new myapp
2. Create the IDE module
Start the play console:
cd newapp
play
Create the module:
idea with-sources=yes
exit
3. Configure the IDE
- Open the newly created project
- Open the module settings(select project and press F4)
- Add the Scala library to your project
- Select Modules->myapp->Dependencies
- Press the plus Icon and select Library(2)
- Add the Scala 2.10.0 Project Library
- Select the Compiler Library in the Scala Facet
- Select Facets->Scala(myapp)
- Set the Compiler library to Scala 2.10.0
- Fix the errors
- Select Modules->myapp-build->Dependencies->scala-2.9.2 and press the minus icon
- Select Libraries->Scala 2.9.2 and press the minus icon
- Fix the output Path for the myapp-build module
- Select Modules->myapp-build->Paths
- Append classes to the Output path(X:projectsmyappprojectargetscala_2.9.2classes)
- Append test-classes to the Test output path(X:projectsmyappprojectargetscala_2.9.2est-classes)
4. Run a test
Select the ApplicationSpec under the test directory and click Run 'ApplicationSpec' from the context menu. You should get an error that the compiled template could not be found. This is because the IDE doesn't compile the templates, but this can be done by run the application once. Also follow point 5 and then run the test again.
5. Run the application
Select a controller and click Run Play 2 App from context menu. This should start the application on address: http://localhost:9000/
.
6. Update dependencies
If you update your application dependencies then you must tell the IDE about this changes. Also after running the play update command you must close the IDE and remove some files from project directory. If you execute the play idea
command before removing the files, you get double dependencies in your play project.
Execute the following steps to update your dependencies:
- Run the
update
task from your play console
- Remove the
.idea_modules
and .idea/libraries
directories
- Run the
idea with-sources=yes
command in the play console
- Run step 3 again
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…