Intellij compile failures: “is already defined as”

后端 未结 10 1698
北海茫月
北海茫月 2021-02-03 17:14

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 pr

相关标签:
10条回答
  • 2021-02-03 17:32

    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.

    0 讨论(0)
  • 2021-02-03 17:41

    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".

    0 讨论(0)
  • 2021-02-03 17:44

    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
    0 讨论(0)
  • 2021-02-03 17:45

    In my case, the problem was the protobuf Idea plugin:

    1. Remove the idea protbuf plugin.
    2. Close Idea
    3. Remove all folders related with idea (.idea and .idea_modules)
    4. Open Idea and Import the project again.
    0 讨论(0)
提交回复
热议问题