Is it possible to configure SBT to use a completely different library version when cross building, depending on the scala version the project is being built with?
For example:
2.9.2
I want to use "org.scalatest" % "scalatest_2.9.2" % "2.0.M5" % "test"
2.10.0
I want to use "org.scalatest" % "scalatest_2.10.0-RC5" % "2.0.M5-B1" % "test"
We recommend that you upgrade to sbt versions 1.0 and later which are compatible with the Scala version 2.12 (requires Java 8).
Background. update resolves dependencies according to the settings in a build file, such as libraryDependencies and resolvers . Other tasks use the output of update (an UpdateReport ) to form various classpaths. Tasks that in turn use these classpaths, such as compile or run , thus indirectly depend on update .
Typically, if a key has no associated value in a more-specific scope, sbt will try to get a value from a more general scope, such as the ThisBuild scope. This feature allows you to set a value once in a more general scope, allowing multiple more-specific scopes to inherit the value.
SBT's crossScalaVersions allows projects to compile with multiple versions of Scala. However, crossScalaVersions is a hack that reuses projects by mutates settings.
Something like this should work:
libraryDependencies <+= scalaVersion(scalatestDependency(_))
def scalatestDependency(scalaVersion: String) = scalaVersion match {
case "2.9.2" => "org.scalatest" % "scalatest_2.9.2" % "2.0.M5" % "test"
case "2.10.0" => "org.scalatest" % "scalatest_2.10.0-RC5" % "2.0.M5-B1" % "test"
}
I assumed that you actually meant that the library versions should be the other way around? :-)
You can see variations on this theme in the ScalaMock 2 build.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With