Search code examples
scalasbtscalatest

Unable to resolve org.scalatest#scalatest;3.0.1: not found dependency issue


Newbie in scala here, going through a scala tutorial.

I am trying to use scalatest as mentioned in the tutorial but getting this error:

[error] (*:update) sbt.ResolveException: unresolved dependency: org.scalatest#scalatest;3.0.1: not found

> scalaVersion
[info] 2.10.6

My build.sbt file looks like this:

name := "tasky"
version := "0.1.0"
libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.1"
libraryDependencies += "org.scalatest" % "scalatest" % "3.0.1" % "test"

Also as mentioned here, I have created the global.sbt and plugins.sbt file at the respective locations with the required details. But, I am still getting the error:

[info] Updating {file:/home/tushar/lsbt/tasky/}tasky...
[info] Resolving org.scalatest#scalatest;3.0.1 ...
[warn]  module not found: org.scalatest#scalatest;3.0.1
[warn] ==== local: tried
[warn]   /home/tushar/.ivy2/local/org.scalatest/scalatest/3.0.1/ivys/ivy.xml
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/org/scalatest/scalatest/3.0.1/scalatest-3.0.1.pom
[warn] ==== local-preloaded-ivy: tried
[warn]   /home/tushar/.sbt/preloaded/org.scalatest/scalatest/3.0.1/ivys/ivy.xml
[warn] ==== local-preloaded: tried
[warn]   file:////home/tushar/.sbt/preloaded/org/scalatest/scalatest/3.0.1/scalatest-3.0.1.pom
[warn] ==== Artima Maven Repository: tried
[warn]   http://repo.artima.com/releases/org/scalatest/scalatest/3.0.1/scalatest-3.0.1.pom 
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: org.scalatest#scalatest;3.0.1: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn] 
[warn]  Note: Unresolved dependencies path:
[warn]      org.scalatest:scalatest:3.0.1 (/home/tushar/lsbt/tasky/built.sbt#L4-5)
[warn]        +- default:tasky_2.10:0.1.0
[trace] Stack trace suppressed: run last *:update for the full output.
[error] (*:update) sbt.ResolveException: unresolved dependency: org.scalatest#scalatest;3.0.1: not found

Any pointers to resolve this issue?


Solution

  • you should use %% instead of a single % as shown below. the %% changes the artifact from scalatest to scalatest_2.10 since the version of scala used in the project is 2.10.

    libraryDependencies +=  "org.scalatest" %% "scalatest" % "3.0.1" % "test"
    

    You can either use %% or specify the artifact_id explicitly as below

    libraryDependencies +=  "org.scalatest" % "scalatest_2.10" % "3.0.1" % "test"
    

    the former approach is recommended over the later.

    Explanation

    Scala's minor version's are not backward compatible. so a library compiled with 2.10 version cannot be used in a project using scala 2.11. So a library has to be published by compiling it for each versions separately (2.10, 2.11 and 2.12 for eg).

    thus all Scala artifacts are published with scala version suffixed at the end. Thus scalatest has a artifact scalatest_2.10,scalatest_2.11 and scalatest_2.12.

    In order to make it easier to select the right version of the artifact in your SBT build depending on your scala version , SBT provides a convient symbol %% that will change the artifact id by appending the scala version for you. Thus if "org.scalatest" %% "scalatest" % "3.0.1" would translate to org.scalatest#scalatest_2.10;3.0.1 on your build dynamically.