如何使用sbt-cross-building和sbt 0.13在sbtPlugin中为每个sbtVersion指定不同的libraryDependencies?

时间:2013-12-13 23:31:30

标签: scala sbt

我将Sbt Cross Building Plugin与sbt 0.13.1一起使用。它工作正常,但我必须为所有定义的CrossBuilding.crossSbtVersions指定较低的公共依赖版本。

如何定义libraryDependencies,以便每个sbtVersion in sbtPlugin使用最新的依赖版本?

2 个答案:

答案 0 :(得分:4)

CrossBuilding.crossSbtVersions := Seq("0.12", "0.13")build.sbt的以下解决方案效果很好:

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")
}

SBT cross building - choosing a different library version for different scala version的启发。

答案 1 :(得分:3)

这是你想要的吗?

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")
}

它会错误地选择“0.121”之类的东西。你可以有一个正则表达式匹配器:

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

然后使用case V012() => ...