Joan
Joan

Reputation: 4300

SBT + Idea 13 => Cannot resolve symbol

I'm using SBT + Idea 13.1.1 and I have all my SBT file in red:

name := "Transformer"

version := "1.0"

libraryDependencies ++= Seq(
  "com.github.scopt" %% "scopt" % "3.2.0",
  "org.scalatest" % "scalatest_2.10" % "2.1.0" % "test"
)

It's saying

Cannot resolve symbol name/version

But Seq is ok. But it's all good to run the app from SBT cmd or even from Idea directly running the main or scalatests. I know it's not a lot information to troubleshoot but I don't know what to check else. Tell me if you have an idea I'll provide everything.

Cheers

Upvotes: 36

Views: 25059

Answers (9)

Raimond
Raimond

Reputation: 1

The problem here seems to be changes in the recent JDK (I was using Ver 16) the sbt project build engine doesn't expect. In IntelliJ this causes the build.sbt to be misread - so that sbt does not recognise Seq.

Scala 2 code is based around JDK 8-11, what you would expect from its age - later changes to the JDK16 string class looks broken to sbt (version 1.28) IntelliJ reports:

error while loading String, class file '/modules/java.base/java/lang String.class' is broken

Setting the JDK to 8-11 resolves the problem.

Upvotes: 0

artin2
artin2

Reputation: 146

In case none of the other solutions work and you are in the same boat as me, where you see a Cannot resolve symbol ... in the build.sbt and all files that have sbt dependencies, and where there are no sbt dependencies in External Libraries, running File | New | Module from Existing Sources... and selecting the build.sbt may fix it for you as it fixed it for me.

Upvotes: 3

yasemin dogan
yasemin dogan

Reputation: 1

It was about the .idea folder, if it is not included the codeStyles, Modules, libraries , it is giving that error. I fix it with import that folder from another project that has it.Then restart IntelliJ.

Upvotes: 0

Jono
Jono

Reputation: 948

I had a similar problem when I updated to SBT 0.13.7. IntelliJ started marking operators such as := and ++ in red with message "Cannot resolve symbol"

My steps to fix this solution were as follows:

  1. In IntelliJ under Files | Settings, I switched my SBT Runner to use a Custom Launcher (and gave my path to sbt-launch.jar which for me was /opt/sbt/bin/sbt-launch.jar).

  2. After testing that I can still compile after #1 above, I then had to invalidate the cache and restart; under Files | Invalidate Caches / Restart...

That's it! :-)

Upvotes: 28

soote
soote

Reputation: 3260

Updating my build.properties from 0.13.8 to a newer version, like 0.13.15, solved it for me. Reference github issue.

Upvotes: 1

Alvaro Pereyra
Alvaro Pereyra

Reputation: 11

Restarting IntelliJ fixed it for me.

Upvotes: 0

Neil
Neil

Reputation: 8594

I had a similar problem on 14.1.2; in my case adding

libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.1" % "test"

and then trying to

import org.scalatest._

Would resulted in: cannot resolve symbol scalatest

Downgrading sbt (0.13.8 -> 0.13.7); in build.properties solved the problem.

here are more details.

Upvotes: 1

Reeebuuk
Reeebuuk

Reputation: 1381

Had the same problem in IDEA 14.0. Nothing above worked.

Upgrade to IDEA 14.1.1 did the trick.

Upvotes: 0

Joan
Joan

Reputation: 4300

To fix this, remove the folder .idea and reimport the project.

The root cause remains a mystery...

Upvotes: 64

Related Questions