简体   繁体   中英

IntelliJ 13's compiler doesn't find errors in Play projects but the highlighter does

I've been trying to get IntelliJ's compilation to inform me of errors in my source code in a multi-module project using Play Framework 2.3.3 and Scala 2.11.2 - IntelliJ is version 13.1.4 (latest stable, Ultimate Edition).

The multi-module projects is layed out very similarly to the play-multidomain-seed project by Adrian Hurt, see https://github.com/adrianhurt/play-multidomain-seed or in the Typesafe Activator for further reference. The hierarchy looks like the following:

/root
   /app
      ...
   /conf
      ...
   /modules
      /module1
         /app
            ...
         /conf
            ...
      /module2
         /app
            ...
         /conf
            ...

The root project has a build.sbt as well as a project directory containing a Scala object that holds common settings and helper methods to be used in the build process. Each sub-project is located in modules folder and also has a build.sbt that is referenced in the build.sbt at the root level.

Now if I used the before mentioned play-multidomain-seed project template, I can get everything up and running fine using activator / sbt . After I import the project into IntelliJ using the "Import SBT project" feature I can work with it but when I run a compile (ie CTRL+F9 for "Make project" -- it doesn't matter if I run an incremental compilation or a full re-compile) it will not show up any compile-time errors (such as unresolvable symbols or other syntax errors). The Scala highlighter in the code editor will show them with a correct error message! Running a compile in sbt / activator on the command line will find the error while IntelliJ simply says "Compilation completed successfully".

The interesting part is that this seems to only happen with sub-projects that are Play projects, a library project using the standard folder layout (ie sources in src/main/scala etc.) works just fine - ie I get correct compiler feedback from IntelliJ. Source and Resource pathes are set correctly according to IntelliJ's "Project Structure" dialog, ie the Play sub-projects use app as their source folder.

I have another project based on Play 2.2.x that uses a single Build.scala file instead of individual build.sbt files and works just fine - I haven't really figured out how to "port" the Build.scala file over to Play 2.3 however since they've changed quite a few things and the docs say that build.sbt is (as far as possible) the best practice.

I haven't started re-installing Scala/Play plugins. I might try this out with the EAP of IntelliJ 14 to see if that changes anything. I have tried the "Import SBT project" method of getting the project into IntelliJ as well as Play Framework's idea command and the gen-idea command of the sbt-idea plugin (which should be roughly similar to what Play does because it is using some version/fork of this plugin I think). Changing the "Incremental compilation by" setting in Settings -> IDE Settings -> Scala from "IntelliJ IDEA" to "sbt incremental compiler" doesn't change anything either.

Anyone out there that has seen this issue as well or any ideas on what I could try? This is making me sad :).

TL;DR

If I have an error in a Scala source file the compilation process initiated by IntelliJ will not report it, sbt on the Console however will correctly report it. The IntelliJ highlighter (in the code editor) also marks it as an error with the correct error message (eg "Cannot resolve symbol xyz"). This only happens for Play modules, and not for "standard" library projects. I presume the compiler is simply not compiling the source files in the Play modules for a reason that I don't understand.

So after all this nice confusion it turns out this is a problem with the version 0.41 of the Play2 Support plugin for IntelliJ since downgrading the Scala and Play 2 plugins to 0.38.441 fixes my problem. You can find those versions at http://plugins.jetbrains.com/update/index?pr=idea&updateId=16633 and http://plugins.jetbrains.com/update/index?pr=idea&updateId=16634 .

The bug in question seems to be this one: http://youtrack.jetbrains.com/issue/SCL-7423 - it's not officially confirmed that this really causes this issue, but it seems nonetheless very related and quite major.

The reason why I thought it was related to the build.sbt files was that while refactoring build.sbt to Build.scala I installed the IntelliJ 14 EAP which updated the Scala/Play plugins and since the plugin folder is shared between IntelliJ 13 and 14 EAP it simply overwrote them. When I then switched back to IntelliJ 13 because 14 EAP didn't fix the problem, I only downgraded/reactivated the 0.41 version of the Scala plugin while the Play plugin remained deactivated - activating it again in version 0.41 made the issue re-appear.

What a journey.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM