Intellij compile failures: "is already defined as"

For me, the reason is that both myproject/src and myproject/src/main/scala are marked as Source. So intellij failed to build myproject/src/main/scala due to above errors. Unmark Source from myproject/src (in intellij, File->Project structure, select myproject Module, select src folder in Sources Tab, remove it from Source in the "Add Content Root" pane) solved the problem. Hope this helps.


It means there are two compiled classes with identical package and class name found in your classpath. One compiled by sbt, one compiled by IntelliJ.

One of the following should be able to solve the issue:

  1. try to generate IntelliJ .iml file with sbt-idea rather than import directly.
  2. sbt clean before click Build -> Rebuild in IntelliJ
  3. when rebuilding with IntelliJ, make sure sbt is not running

I ran into this issue today on IntelliJ 2021.2.1 and according to this page it's some issue with IntelliJ's incremental compiler for Scala, so the solution is to change the "Incrementality Type" from "IDEA" to "Zinc" in Preferences -> Build, Execution, Deployment -> Compiler -> Scala Compiler


I had the same problem and @Max is right, there is a conflict with the compiled classes, but the solution provided didn't work for me. It turns out that I was using sbt-idea to generate the IDEA project structure as a workaround of an Intellij IDEA 14 + scala plugin bug on the SBT import, that is not fixed yet at the time I write this.

In order to fix it, I had to remove src_managed/main/controller that was in conflict with src_managed/main in the Module settings because of an sbt-idea bug. So double-check your module source folders and make sure you don't have subfolders in conflict with a parent folder already declared as source.


You need to change "Settings -> Build,Execution,Deployment -> Scala Compiler -> Compile order" from "Mixed" to "Java then Scala". If you have compile the project previous, you should first run "sbt clean".