Play Framework 2.4 and IntelliJ Idea
Asked Answered
P

5

14

I am trying to open a play 2.4 project in IntelliJ but since things have changed I don't know how to do this.

In previous versions I could just run

activator idea

Or use the activator UI and click on generate intelliJ project, but in 2.4 the idea command doesn't seem to exist

[error] Not a valid command: idea (similar: eval, alias)
[error] Not a valid project ID: idea
[error] Expected ':' (if selecting a configuration)
[error] Not a valid key: idea (similar: clean)
[error] idea
[error]     ^

And the UI seems broken, when I click on generate intelliJ project it tries to compile the app and gives this error:

play/Play$
java.lang.NoClassDefFoundError: play/Play$
Use 'last' for the full log.
Failed to load project.

I created the project from scratch using the play java template with:

activator new

I have also tried importing the folder as a project but intelliJ doesn't seem to identify it as a project

Pyretic answered 2/6, 2015 at 20:19 Comment(4)
Although I could be cheeky and copy this as an answer, here you go: https://mcmap.net/q/828554/-why-does-sbt-fail-with-noclassdeffounderror-play-play-in-play-2-2-x-projects-after-sbt-compile-in-play-2-3-project. I tried it, and it works. Create a project with activator, delete this file and open it with Idea.Assassin
Make sure that you are using JDK 8 (Intellij IDEA, JAVA_HOME system variable)Cantilever
I'm having a somewhat similar issue where IntelliJ doesn't see all the test classes on the CE version.Incompatible
I had this same issue and I fixed by deleting the .idea folder and re-importing the project.Unlimited
B
18

I run into the same problem, as I used IDEA to open a project folder, it had an play 2 app in a sub folder, then I import module (play 2 app) to the system.

And it works well.

After that I have changed the module folder name, then when I run the app, it displayed:

Not a valid project ID: "project team"

I re-checked the folder, and found that in the File -> Project Structure option, the name of module is "root", and the "team" is the module for whole project (not the module imported by SBT), so apparently, the module wasn't functional after I changed the module folder name.

So I found and removed all .idea folder, which is IDEA configureation, then re-open/re-import the module, still not work. I thought it's IDEA cache issue, it do have cache for the opened project, so I changed the project folder from team to something else, clean the .idea folders, and re-open/re-import it. It worked.

If the play app is in the project folder as a sub folder, to import the module at File -> Project Structure.

The project name should be "root" when running it in IDEA. So in this case, you should rename "project team" to "root" in the name field.

enter image description here

enter image description here

Burweed answered 23/12, 2015 at 10:46 Comment(3)
ROOT - this was the root of my problems! thanks a lot :)Adore
Thanks! After renaming the module as 'root', all is well.Dabney
Thanks! It's clearly a bug. I found your answer after I filed ticket youtrack.jetbrains.com/issue/SCL-13988Dulci
N
6

Solution 1

In my case (IDEA 2018.2), I changed the lazy val variable in build.sbt, it had the name "root" when my project name was "top", changed "root" to "top".

Before:

lazy val root = (project in file(".")).enablePlugins(PlayScala)

After:

lazy val top = (project in file(".")).enablePlugins(PlayScala)

Change project variable

Solution 2

The method proposed by Tom solved my problem partially, because after rebooting the IDEA I returned the project name back, it was necessary to change the variable from "top" to "root" in build.sbt.

Before:

name: = "top" 

After:

name := "root"
Nanananak answered 2/8, 2018 at 4:24 Comment(0)
C
2

Intellij IDEA lets you quickly create a Play application without using a command prompt. You don’t need to configure anything outside of the IDE, the SBT build tool takes care of downloading appropriate libraries, resolving dependencies and building the project.

Before you start creating a Play application in IntelliJ IDEA, make sure that the latest Scala Plugin is installed and enabled in IntelliJ IDEA. Even if you don’t develop in Scala, it will help with the template engine and also resolving dependencies.

Basically, install Play Framework, Scala plugins and import project into Intellij as SBT project. Don't use activator to create IDEA project files. More details here.

Cattegat answered 2/6, 2015 at 22:17 Comment(3)
He could use the plugin only if he has IDEA Ultimate.Assassin
True, but it is not clear from the question whether its Ultimate.Cattegat
And does not work if you want to create it using the java seedBeadruby
P
2

It seems I had not updated scala/sbt to the latest version in intelliJ Once I had done this it noticed that it was a valid project, though the docs don't seem to mention you can import it as an SBT project, just how to create it as a new sbt project (which I did not want to do as I wanted to create it via activator)

I also had the project/play-fork-run.sbt file issue

Pyretic answered 3/6, 2015 at 9:46 Comment(1)
No need to import it (if you are thinking on New > From Existing Sources). You can plainly open it after it has been generated with the activator.Assassin
C
0

I use Intellij Idea 16.3.3 and this problem appears sometimes. How I fixed it? You just need to open your SBT plugin and under your project get the context menu then you should choose "Ignore SBT project". After a current process is finished you should turn on this option again. This is work for me:)

Convocation answered 25/1, 2017 at 11:23 Comment(1)
You should add more clear information about what you're suggesting. What is "Open your SBT Plugin" and I couldn't find any of your described steps.Cuthburt

© 2022 - 2024 — McMap. All rights reserved.