I've got a scala project that compiles, runs and tests fine when using SBT from the command line. However, when building the project in intellij, it seems every class in the project has this error in the event log, causing the build to fail:
SendCommandToService is already defined as case class SendCommandToService
case class SendCommandToService(service: String, commandName: String, keys: Array[String], values: Array[String])
^
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With