3
votes

I use Sbt Cross Building Plugin with sbt 0.13.1. It works fine, but I had to specify the lower common dependency versions for all the CrossBuilding.crossSbtVersions defined.

How can I define libraryDependencies so it uses the most recent dependency version per sbtVersion in sbtPlugin?

2

2 Answers

4
votes

The following solution for CrossBuilding.crossSbtVersions := Seq("0.12", "0.13") in build.sbt works well:

libraryDependencies <++= (sbtVersion in sbtPlugin) { version =>
  val V013 = """0\.13(?:\..*|)""".r
  val (scalaz, scalatest) = version match {
    case V013() => ("7.1.0-M4", "2.0.1-SNAP3")
    case _ => ("7.0.5", "2.0.M6-SNAP3")
  }
  Seq(
    "org.scalaz"    %% "scalaz-concurrent" % scalaz    % "embedded",
    "org.scalatest" %% "scalatest"         % scalatest % "test")
}

Inspired by SBT cross building - choosing a different library version for different scala version.

3
votes

Is this what you want?

libraryDependencies <++= (sbtVersion in sbtPlugin) { version =>
  val (scalaz, scalatest) = version match
    case v if v startsWith "0.12" => ("7.0.5", "2.0.M6-SNAP3")
    case v if v startsWith "0.13" => ("7.1.0-M4", "2.0.1-SNAP3")
  }

  Seq(
    "org.scalaz" %% "scalaz-concurrent" % scalaz % "embedded",
    "org.scalatest" %% "scalatest" % scalatest % "test")
}

It will pick things like "0.121" incorrectly. You could have a regex matcher for that:

val V012 = """0\.12(?:\..*|)""".r
val V013 = """0\.13(?:\..*|)""".r

And then use case V012() => ..., etc.