Intellij IDEA can not resolve symbol with Play framework

前端 未结 7 1311
太阳男子
太阳男子 2020-12-03 02:58

I am using IDEA 13 with Play 2.2.1 and was doing the examples on the play site.

public static Result index() {
   return redirect(routes.Application.tasks())         


        
相关标签:
7条回答
  • 2020-12-03 03:17

    I had a similar problem when testing my controller. I 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).

    The last version of the SBT support for IDEA did 90% of the work. Then F4 to enter module settings dialog. Set up your project dependencies like in the picture below (the bright red folder have been set by IDEA and do not exist yet in my project so do not worry if they do in yours). It is a matter of including managed classes and generated code in the code that idea will use and index.

    enter image description here

    now I can use code like this from within IDEA and debug it no problem.

    Result result = Helpers.callAction(controllers.routes.ref.CrudController.createEntity(CrudEntities.contact.name()),
            new FakeRequest().withJsonBody(paramJson)
    );
    

    your way of doing it should work as well.

    0 讨论(0)
  • 2020-12-03 03:18

    In my case running the sbt command from a user that doesn't have permission for the project you're entering sbt in. Clean up and then change folder permissions with chown -R yourUser /path/to/project and it should fix it. After that ./sbt compile

    0 讨论(0)
  • 2020-12-03 03:21

    These steps work for me: add following lines to your plugins.sbt file:

    resolvers += "sbt-idea-repo" at "http://mpeltonen.github.com/maven/"
    addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.2.0")
    but if you don't know the correct version of sbt-idea then use this instead:
    addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "latest.integration")
    

    Warning - It will take too much time to build as it need to parse all the version and get the latest version.

    Run this command -

    sbt gen-idea
    
    0 讨论(0)
  • 2020-12-03 03:29

    Well I am using "IntelliJ Idea 13" and doing "sbt" Playframework project with "Activator". After everything tried, I finally solved this issue with following steps in terminal/cmd at my existing root sbt project

    1. enter this command in terminal/cmd : sbt clean
    2. then delete these files and folders : ".idea", "all _.iml files" , "all target folders reside in project folder(this may not be necessary but I did it.)"
    3. enter this command in terminal/cmd: sbt idea
    4. now in IntelliJ : open project

    Note: If you are building the Playframework project with "Play" command instead of "Activator" instead of sbt idea command you can try play idea or play "idea with-sources=yes"

    Hope this will help you.

    0 讨论(0)
  • 2020-12-03 03:29

    I had to add the below plugin entry to my plugins.sbt (under projects folder) for intellij IDEA to resolve play variables like routes etc.

    addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.6.0")

    Note: After adding the above plugin to plugins.sbt, run the below commands to rebuild idea and resolve the issue:

    • activator clean
    • activator idea
    0 讨论(0)
  • 2020-12-03 03:33

    I could solve the problem by marking the generated code directories as the "Sources" folder. Go to File -> Project Structure -> "root" module -> Sources.

    0 讨论(0)
提交回复
热议问题