What's the problem with this "routes" that are not found in IntelliJ IDEA 14?
have you tried without the ***
?
return redirect(routes.Application.index();
cannot resolve symbol routes
. How to get resolved with this ? Need help. –
Farris According to the documentation:
For each controller used in the routes file, the router will generate a ‘reverse controller’ in the routes package, having the same action methods, with the same signature, but returning a play.mvc.Call instead of a play.mvc.Result.
Reverse controllers are generated when an application is compiled. It follows that you need to compile your application in order to make these classes accessible in your IDE. To make sure that Idea finds files correctly you can right-click target's subdirectory which contains generated classes and mark it as a source directory.
I've hit this problem a few times. For me, the project would compile with sbt
, but Intellij had trouble resolving references. Here are some causes I've found:
Cause 1: Namespace Confusion
One cause for this I have hit a couple of times is that Intellij gets confused about namespaces due to some wildcard imports - it's not actually related to project configuration.
For example, we've found that if you import play.api._
, then Intellij won't be able to resolve import controllers.routes
(or anything else in controllers
). If you switch them around though, it's okay.
You can test if this is the problem by moving your imports around, or seeing if the same imports work in different files.
To check if Intellij really can't resolve your class, try referencing the class from _root_
. With my example above, Intellij was always able to resolve _root_.controllers.routes
, so I knew it wasn't an issue related to how my project was configured.
(I wouldn't leave that _root_
in the code though, it's a bit ugly and confusing I think! Someone will just delete it and then the problem will come back. Instead I'd try to remove wild card imports)
Cause 2: generated sources aren't marked as "Sources"
Classes like routes
and other template classes inside view
are auto-generated. It's possible the project isn't configured correctly and Intellij doesn't realize that there are auto-generated routes and twirl source files.
On my system, those auto-generated folders live in target/scala-[VERSION]/
as src_managed
(all the routes stuff) and twirl
(all the templates stuff).
To check/fix this, do:
- File -> Project Structure
- select "Modules" in the left pane
- select the relevant module in the centre pane
- select the "Sources" tab in the right pane
- find the folders mentioned above inside
target
and marksrc_managed/main
andtwirl/main
as "Sources" (note you mark themain
folders, not the outer folders)
Cause 3: target
is excluded
I have found that sometimes when you import a project, Intellij automatically marks the target
dir as excluded. This means the "Sources" inside it are effectively ignored. So make sure that your auto-generated sources don't lie within some excluded directory.
To fix this follow the instructions in 2 and make sure that there are no special markings for the target
folder. In my version of Intellij, that means the icon is a normal brown colour - not red or blue.
If you've had to do this, then it's possible that all the directories inside target
are not excluded. For completeness sake, I'd recursively mark all the directories (like resolution-cache
and streams
) as excluded so that only the twirl and routes source directories are left not excluded.
We hit these problems a lot unfortunately as a team. One trick we use is to just copy/paste each other's .idea/modules/root.iml
files as that's where all the config lives. So if one developer has a working setup, just copy over their Intellij conf to your own machine.
This is a snippet of my conf which relates to how sources and excludes are configured (it essentially replicates the steps in 2 and 3 above). I use it for a play 2.3 app and it works. You can try merging it into your root.iml
if you have other complex config or dependencies which auto-generate code, or just replace your content
element with this if you have a simple play project:
...
<content url="file://$MODULE_DIR$/../..">
<sourceFolder url="file://$MODULE_DIR$/../../app" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/../../app-2.11" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/../../target/scala-2.11/src_managed/main" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/../../target/scala-2.11/twirl/main" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/../../target/scala-2.11/src_managed/test" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/../../target/scala-2.11/twirl/test" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/../../test" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/../../test-2.11" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/../../conf" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/../../target/scala-2.11/resource_managed/main" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/../../target/scala-2.11/resource_managed/test" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/../../test/resources" type="java-test-resource" />
<excludeFolder url="file://$MODULE_DIR$/../../target/resolution-cache" />
<excludeFolder url="file://$MODULE_DIR$/../../target/streams" />
</content>
...
have you tried without the ***
?
return redirect(routes.Application.index();
cannot resolve symbol routes
. How to get resolved with this ? Need help. –
Farris I solved executing this two steps specified in this other thread https://mcmap.net/q/442931/-intellij-idea-can-not-resolve-symbol-with-play-framework
(I'm using Idea 15.0.1)
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.6.0")
Then execute command:
sbt gen-idea
As biesior suggests, this worked for me:
return redirect(controllers.routes.Application.index());
© 2022 - 2024 — McMap. All rights reserved.
redirect(controllers.routes.App...
– Diclinousroutes
file into thetarget
folder from there it could be used. – EardrumRoutes
classes, so this is not a problem. Can you also try something likecontrollers.package.routes.ClassName
wherepackage
is the name of your subpackge, if there is one. – Eardrum