41

After changing my build.sbt file in IntelliJ, I get this strange error report where it appears that "keys" (I don't know what these keys even are) are colliding with themselves. Researching this error message only finds github pull requests where people are requesting library maintainers to prefix their keys to avoid key collisions. How can these built-in IntelliJ keys collide with themselves? It makes no sense. Here is the excerpt from the stack trace:

java.lang.RuntimeException: Some keys were defined with the same name but different types: 
'ssExtractBuild' (sbt.Task[org.jetbrains.sbt.structure.BuildData], sbt.Task[org.jetbrains.sbt.structure.BuildData]), 
'settingData' (sbt.Task[scala.collection.Seq[org.jetbrains.sbt.structure.SettingData]], sbt.Task[scala.collection.Seq[org.jetbrains.sbt.structure.SettingData]]), 
'taskData' (sbt.Task[scala.collection.Seq[org.jetbrains.sbt.structure.TaskData]], sbt.Task[scala.collection.Seq[org.jetbrains.sbt.structure.TaskData]]), 
'extractStructure' (sbt.Task[org.jetbrains.sbt.structure.StructureData], sbt.Task[org.jetbrains.sbt.structure.StructureData]), 
'ssExtractDependencies' (sbt.Task[org.jetbrains.sbt.structure.DependencyData], sbt.Task[org.jetbrains.sbt.structure.DependencyData]), 
'ssExtractProjects' (sbt.Task[scala.collection.Seq[org.jetbrains.sbt.structure.ProjectData]], sbt.Task[scala.collection.Seq[org.jetbrains.sbt.structure.ProjectData]]), 
'ssExtractAndroid' (sbt.Task[scala.Option[org.jetbrains.sbt.structure.AndroidData]], sbt.Task[scala.Option[org.jetbrains.sbt.structure.AndroidData]]), 
'ssExtractRepository' (sbt.Task[scala.Option[org.jetbrains.sbt.structure.RepositoryData]], sbt.Task[scala.Option[org.jetbrains.sbt.structure.RepositoryData]]), 
'ssOptions' (org.jetbrains.sbt.Options, org.jetbrains.sbt.Options), 
'commandData' (sbt.Task[scala.collection.Seq[org.jetbrains.sbt.structure.CommandData]], sbt.Task[scala.collection.Seq[org.jetbrains.sbt.structure.CommandData]]), 
'ssExtractProject' (sbt.Task[scala.collection.Seq[org.jetbrains.sbt.structure.ProjectData]], sbt.Task[scala.collection.Seq[org.jetbrains.sbt.structure.ProjectData]]), 
'ssExtractPlay2' (sbt.Task[scala.Option[org.jetbrains.sbt.structure.Play2Data]], sbt.Task[scala.Option[org.jetbrains.sbt.structure.Play2Data]])

And the full stack trace is here: https://pastebin.com/ymZvgMCj

This happened after I added a dependency to my build.sbt. I thought it was the problem at first and tried removing it, but now my build.sbt doesn't even work in its previous state! I've cleared my intellij's cache, restarted, deleted my .idea folder in that project entirely and reimported the entire project itself into intellij, and I still have the same problem. What could have happened between the last time I changed my build.sbt and now that would break the project like this?

K. M
  • 867
  • 1
  • 8
  • 17
  • You could follow this link: https://users.scala-lang.org/t/sbt-error-some-keys-were-defined-with-the-same-name-but-different-types/4585 – Chema Sep 16 '20 at 10:05

7 Answers7

101

Go to

Preference -> Build, Execution, Deployment 
                  -> SBT 
                      -> check "Use SBT shell for build and import" 
                           -> Press OK

You can now refresh SBT projects and it should work . if you want, you could uncheck "Use SBT shell for build and import" and it will also work

prayagupa
  • 30,204
  • 14
  • 155
  • 192
feleio
  • 1,170
  • 1
  • 6
  • 6
  • 1
    Interesting proposition, I haven't had this issue come up since I fixed it by nuking intellij entirely but I will definitely give this a try if it comes up again. I don't entirely understand where the "Use SBT shell for build and import" option comes into play here - I am able to refresh SBT projects even when I do not have that option ticked. (although obviously in my original case, refreshing SBT projects without that option ticked did not fix the problem) – K. M Jan 29 '18 at 20:07
  • 3
    Awesome, worked like a charm. Not sure what's the real issue here and how does it get fixed, by checking that option. Since, I check that option, it just imports the libs using sbt shell and I see the logs there. But, how does it get fixed by that? I have faced this 2-3 times now on different projects and would like to have a permanent answer. – Sagar Kulkarni Feb 12 '18 at 12:21
  • 1
    This worked for me. I did this option, clicked "apply" and had it build once. Then I undid this setting, because I prefer to have it run in IntelliJ than SBT, and the fix still held. – NateH06 Mar 07 '18 at 20:35
  • Worked like a charm .. Thanks ! – sid_bond Jul 16 '20 at 05:55
4

I too had the same issue, I 'fixed' it by nuking and reinstalling IntelliJ.

Intellij Version: IntelliJ IDEA 2017.2.5 Build #IU-172.4343.14 Scala Plugin Version: 2017.2.13

Steps that did not work

  • Switching git branch
  • Invalidate caches / Restart
  • Removing .idea directory & reimport
  • Changing SBT config to not use the bundled jar
rahilb
  • 726
  • 3
  • 15
  • 3
    I know this works, but, nuking Intellij every time u get this error seems to be a bad idea. I would suggest to try some other solutions first (like feleio's [answer](https://stackoverflow.com/a/47777860/5906633) on the same thread or any other solutions). – Sagar Kulkarni Feb 12 '18 at 12:26
  • 2
    For what it's worth, **Invalidate Caches and Restart** fixed this for me. – Lachlan May 25 '18 at 03:07
  • removing .idea directory dose work for me , may i ask how to invalidate caches and restart ? – shengshan zhang Jun 01 '18 at 08:10
2

I was just having the same error with latest 2017.3 EAP version of Idea. I couldn't import a project and got the same error. The fix for me was to switch to another branch, import the project (which succeeded), then switch back to the original branch again and reimport the project in Idea (click on sbt refresh button).

There was never a problem running sbt in a terminal, only in Idea. Sounds like an Idea issue...

Allan
  • 81
  • 10
1

I also had this problem when I developed Spark using Intellij Idea, and I fix this by changing the "File -> Settings -> Build Tools -> sbt -> Group modules" to "using qualified names"

and make "File -> Settings -> Build Tools -> sbt -> Use sbt shell for build and import" selected.

user9547302
  • 141
  • 1
  • 3
1

In my case, I had a python module. Renamed externally and intellij fails to do anything related to modules structure. Including sbt refresh.

Use sbt shell didn't fix the issue. Invalidating cache and restart was not helping as well.

I've to delete the sbt.xml inside the project/.idea folder.

This will erase your current sbt settings. Not a bid deal since sbt wasn't working at all.

Douglas Liu
  • 1,592
  • 17
  • 11
1

I had the same issue today. My fix was to :

  • invalidate the cache
  • close Intellij
  • delete .idea
  • import project
0

I experienced this today tried these things, which did NOT fix it:

  • Use SBT shell for build and import (SBT settings)
  • Invalidate the cache and restart

However the problem finally DID go away when I did this:

  • Increase SBT maximum heap size to 6000 (it was 5000)