Why “could not find implicit” error in Scala + Intellij + ScalaTest + Scalactic but not from sbt

前端 未结 6 1322
清歌不尽
清歌不尽 2021-01-07 23:55

I have this code that is working 100% from sbt , executing sbt test but throw a compilation error in Intellij Idea.

import org.         


        
6条回答
  •  爱一瞬间的悲伤
    2021-01-08 00:17

    It's possible some dependencies are transitively including incompatible versions of Scalactic or Scalatest in the compile scope, which also are included in the test scope.

    You can check this in the Project Structure under Project Settings / Modules / Dependencies tab, and analyze it more closely with the sbt-dependency-graph plugin.

    SBT does however perform dependency evictions which IntelliJ does not (issue), which can cause additional problems when compiling from the IDE. If sbt-dependency-graph shows that the conflicting versions are evicted, then it is probably an instance of this issue.

    Workaround: when you find the offending transitive dependency, exclude it from the root dependency in your build.sbt. For example:

    "org.apache.spark" %% "spark-core" % "2.1.0" % "provided" exclude("org.scalatest", "scalatest_2.11")
    

提交回复
热议问题