Saurabh Rana
Saurabh Rana

Reputation: 167

IntelliJ gives errors saying "Cannot resolve symbol " in build.sbt after creating Scala project

On creating a Scala project in IntelliJ, the build.sbt file shows error "Cannot resolve symbol name". When I created a "Hello World" Scala Object, in spite of the error in sbt file, the program ran successfully.

When I added a dependency in the build.sbt for Spark core, it showed "Cannot resolve symbol libraryDependencies", and in the Scala Object, when I added an import for SparkContext import org.apache.spark.SparkContext, it gave "Cannot resolve symbol apache".

I went through the below related post:

IntelliJ inspection gives "Cannot resolve symbol" but still compiles code

and attempted "Invalidate Cache" but it did not resolve the issue.

I also tried deleting the IDEA directory and reimporting the project as below:

  1. Closed IntelliJ.
  2. Went to the project folder and delete the .idea directory.
  3. Opened IntelliJ.
  4. Imported the project again by clicking on File>>New>>Project from existing sources.

However, this too did not resolve the issue.

Also, I tried using a lower version of Scala which did not resolve the issue.

Below are the contents of the build.sbt file:

name := "ScalaApp"
version := "0.1"
scalaVersion := "2.12.12"
libraryDependencies += "org.apache.spark" %% "spark-core" % "2.4.3"

What can be the issue that it shows these errors in build.sbt and despite that the Scala hello world runs fine but not when I add another dependency in build.sbt and include import in the Scala class?

Thanks

Upvotes: 2

Views: 3046

Answers (1)

Saurabh Rana
Saurabh Rana

Reputation: 167

The issue is resolved. The solution that worked for me was to use lower version of SBT 0.x instead of 1.x. While creating the project I selected sbt 0.x version (0.13.18) from the dropdown and it did not give the error in build.sbt and I could continue and add dependencies without the above mentioned errors.

Upvotes: 0

Related Questions