Sbt not resolving org.scalatest


#1

The build.sbt for my project includes:

libraryDependencies += “org.scalatest” %% “scalatest” % “3.2.0-SNAP10” % Test

and when I look at the external libraries I see the library and when I open the library under org.scalatest I see all the symbols I expect to see but when I try to import org.scalatest.WordSpecLike (or anything else from this library ) Intellij tells me that it “cannot resolve scalatest”.

I’ve imported other libraries (e.g. all the various com.typesafe.akka libraries) and not had any problem.

Has anyone else run into this problem?


#2

I should add I’m running IntelliJ IDEA 2018.3.5 (Ultimate)
With version 2018.3.7 of the Scala plugin


#3

Unless you have a special reason to be using 3.2.0-SNAP10, you should use the latest stable release, 3.0.6.

(But, I really don’t know if the problem you’re experiencing is related to this.)


#4

Thanks Seth. I replaced 3.2.0-SNAP10 wih 3.0.6 and that didn’t help. It’s so frustrating because I can see org.scalatest in the library listing and I can’t imagin what kind of bug would object to a package under org but not packages under com.typesafe. I feel like I must be making some stupid mistake but I can’t see what it would be.

I would be really grateful if some IntelliJ user could try it and tell me if they run into the problem. (I filed a bug with JetBrains but haven’t heard anything.)


#5

OK, this has nothing to do with IntelliJ. I get the same error when I run directly in sbt.
This is taken directly from the org.scalatest user guide [http://www.scalatest.org/user_guide]
Here’s my build.sbt

name = “st”
version = “0.1”
scalaVersion = “2.12.8”
libraryDependencies+=“org.scalatest” %% “scalatest” % “3.0.5” % “test”

And here’s my test case

import org.scalatest.FunSpec

class SetSpec extends FunSpec {

describe(“A Set”) {
describe(“when empty”) {
it(“should have size 0”) {
assert(Set.empty.size == 0)
}

  it("should produce NoSuchElementException when head is invoked") {
    assertThrows[NoSuchElementException] {
      Set.empty.head
    }
  }
}

}
}

When I execute compile under sbt I get the error message:

object scalatest is not a member of package org

It’s as if there is an object org shadowing org.scalatest?


#6

Did you put your test case in src/test and not src/main? The % "test" (or % Test) means the ScalaTest dependency is only available in src/test.


#7

Sigh. Thanks Seth!