简体   繁体   中英

How to specify different libraryDependencies per sbtVersion in sbtPlugin with sbt-cross-building and sbt 0.13?

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 ?

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM