0
votes

Starting on two new things at the same time: IntelliJ + Scala (+ Play).

I am having some strange issue on IntelliJ reporting errors on the editor if I import play.api._ on the same class. Project is a new project created with IntelliJ scala+play 2.4 template.

Example file ImportError.scala in app/controllers/subpackage:

package controllers.subpackage

import play.api._
import controllers.ClassToImport

class ImportError {
  val instance = new ClassToImport()
}

IntelliJ editor is givin me error on line "import controllers.ClassToImport": "Cannot resolve symbol ClassToImport"

If I select 'Recompile ImportError.scala", the console gives no compile errors.

If I change the class by removing the play.api import like this:

package controllers.subpackage

import controllers.ClassToImport

class ImportError {
  val instance = new ClassToImport()
}

Then IntelliJ no longer gives me errors on the editor.

Also here are other observations of the situation:

  • If I cut-paste the latter import before the play import, IntelliJ will change my imports to: 'import controllers.ClassToImport' and 'import play.api.{controllers, _}', so here must be some clue. Why does it think I want controllers from play api?
  • If I change the order of the two imports then both editor and compile result are happy.
  • If I change the play import to "import play.api.controllers" then editor is happy but compile result is "object controllers is not a member of package play.api". I do not understand this at all, as to my understanding (as shown by the error) there does not exist play.api.controllers, so why is IntelliJ editor accepting it?

The above example is a isolated example of the problem I am facing in a real project with importing play.api._ with IntelliJ. Should be easily reproducable with the latest IntelliJ IDEA community 2016.2.4.

1
A piece of new information: If I go to the External Libraries of my project and select the "com.typesafe.play:play_2.11:2.4.8.jar" and "Open libary settings" and remove the sources, then issue is resolved. No errors on editor or when doing compile.Raipe

1 Answers

0
votes

The prblem here is that you are importing everything from play.api, and inside that there is a package named controllers.

So, when in the next statement, you try to import controllers.ClassToImport, it is searching class ClassToImport in play.api.controllers, which will fail.

To fix that, you may try to reorder your imports

import controllers.ClassToImport
import play.api._

or rename the play controllers package:

import play.api.{controllers => playControllers, _}
import controllers.ClassToImport