Search code examples
scalatestingsbtcode-coveragescoverage

How do i get sbt to resolve full scala version


I have "org.scoverage" %% "scalac-scoverage-plugin" % "2.0.8" under my library dependencies in my build.sbt, and

scalaVersion := "2.13.1"
lazy val root = (project in file(".")).
  settings(
    name := "<redacted>",
    version := "0.1",
    scalaVersion := "2.13.1"
  )

is up at the top, yet when it tries to resolve, it tries resolve scalaVersion 2.13 not 2.13.1

https://repo1.maven.org/maven2/org/scoverage/scalac-scoverage-plugin_2.13/2.0.8/scalac-scoverage-plugin_2.13-2.0.8.pom

How can i get it to keep the .1 at the end?

Alternatively, im trying to do this instead of just the normal plugin way. but if i try the plugin way addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.8")

I get from running sbt clean coverage test not found: https://repo1.maven.org/maven2/org/scoverage/scalac-scoverage-plugin_2.13.1/2.0.10/scalac-scoverage-plugin_2.13.1-2.0.10.pom

Which doesnt make sense, because no where in my build or anything have I specified 2.0.10 as the lib version.


Solution

  • You are mixing different things here, I'll try to clarify things.


    Regular library dependencies such as could be "org.blabla" %% "whatever" % "a.b.c" do not depend on the minor version y of Scala 2.x.y.

    It is expected that these are retrieved at URLs such as .../org/blabla/whatever_2.13/a.b.c/whatever_2.13-a.b.c.jar. That is only with 2.13 in the URI and not 2.13.y.


    Plugins, such as "org.scoverage" % "sbt-scoverage" % "2.0.8" are (as of today) built with Scala 2.12.

    Note that you don't have to care about this Scala version. It's a different version from the one used to build your app but it doesn't matter.

    Plugins have ability to know the Scala version of the main project and depend on specific JAR for the Scala version of the project.


    Which doesnt make sense, because no where in my build or anything have I specified 2.0.10 as the lib version.

    The plugin in version 2.0.8 depends on library scalac-scoverage-plugin_x.y.z to work which is in version 2.0.10.

    You can see dependencies of the plugin at https://mvnrepository.com/artifact/org.scoverage/sbt-scoverage_2.12_1.0/2.0.8.


    In the end, you should probably not care at all with these details and just rely on latest version of the plugin + upgrade to latest Scala minor version. You don't need to manually depend on the libraries used by the plugin itself.

    That is addSbtPlugin("org.scoverage" % "sbt-scoverage" % "x.x.x") as mentioned in the documentation.


    EDIT: as suggested by another comment, Scoverage itself dropped support for Scala <2.13.5 since version 2.0.10. See release notes.

    Thus, either upgrade your Scala version, or use an older Scoverage SBT plugin (which itself depends on older Scoverage version).