Nick Nick - 1 year ago 220
Scala Question

Intellij compile failures: "is already defined as"

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])

Max Max
Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download