I am trying to use IntelliJ with a play framework 2.11 application.
I installed the Play Framework 2 plugin and the Scala plugin for IntelliJ.
I created a Play application. I have been struggling writing and running Specs 2 tests in IntelliJ. My run config says to run "make" first when running the Specs 2 test, however it doesn't look like my test classes are being generated. Keeps on telling me that it could not find the specification. When I look on the file system, there is no code in target/test-classes, the directory is empty. Further, it seems to take a LONG time to do the build, at least compared to running the Play console.
I wanted to see how people are using Play with IntelliJ. Do you just use IntelliJ as an editor, and run everything through the Play console?
Is there a way whereby you can run your Application tests in IntelliJ (getting your test classes to run)?
I have never had any problem running the Play console and running ~test-only test=xxx.Spec. It has typically been rather fast.
Here is the exception I am getting in IntelliJ when I try to run my Specs2 tests:
Exception in thread "main" java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.jetbrains.plugins.scala.testingSupport.specs2.JavaSpecs2Runner.runSingleTest(JavaSpecs2Runner.java:130) at org.jetbrains.plugins.scala.testingSupport.specs2.JavaSpecs2Runner.main(JavaSpecs2Runner.java:76) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120) Caused by: java.lang.RuntimeException: can not create specification: test.ApplicationSpec at scala.sys.package$.error(package.scala:27) at org.specs2.specification.SpecificationStructure$.createSpecification(BaseSpecification.scala:96) at org.specs2.runner.ClassRunner.createSpecification(ClassRunner.scala:64) at org.specs2.runner.ClassRunner.start(ClassRunner.scala:35) at org.specs2.runner.ClassRunner.main(ClassRunner.scala:28) at org.specs2.runner.NotifierRunner.main(NotifierRunner.scala:24) ... 11 more
To add Scala support to existing module:Right-click the module in Project View, choose “Add Framework Support…” Check “Scala” in technologies list (unavailable if module has Scala facet attached) Provide a path to Scala installation (if not detected)
To start working with Scala in IntelliJ IDEA you need to download and enable the Scala plugin. If you run IntelliJ IDEA for the first time, you can install the Scala plugin when IntelliJ IDEA suggests downloading featured plugins. Otherwise, you can use the Settings | Plugins page for the installation.
To run a Play application: Create a new Run Configuration – From the main menu, select Run -> Edit Configurations. Click on the + to add a new configuration. From the list of configurations, choose “sbt Task”
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
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:
update
task from your play console.idea_modules
and .idea/libraries
directoriesidea with-sources=yes
command in the play consolePlay console includes a fork of a sbt plugin named sbt-idea. The play's fork got a little lagged behind the original plugin, and has some problems in IntelliJ when you run play idea
. You can use the original plugin, which doesn't have any issues. In order to use this plugin in your play project, you need to..
1.Add the following lines to project/plugins.sbt
file: (the blank line in the middle is required)
resolvers += "Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/" addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.5.1")
2.Run gen-idea
from the play console.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With