简体   繁体   English

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

[英]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 . 我使用Sbt Cross Building Plugin和sbt 0.13.1 It works fine, but I had to specify the lower common dependency versions for all the CrossBuilding.crossSbtVersions defined. 它工作正常,但我必须为所定义的所有CrossBuilding.crossSbtVersions指定较低的常见依赖版本。

How can I define libraryDependencies so it uses the most recent dependency version per sbtVersion in sbtPlugin ? 如何定义libraryDependencies以便它sbtVersion in sbtPlugin使用每个sbtVersion in sbtPlugin最新依赖版本?

The following solution for CrossBuilding.crossSbtVersions := Seq("0.12", "0.13") in build.sbt works well: 对下述溶液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")
}

Inspired by SBT cross building - choosing a different library version for different scala version . 灵感来自SBT跨建筑 - 为不同的scala版本选择不同的库版本

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. 它会错误地选择“0.121”之类的东西。 You could have a regex matcher for that: 你可以有一个正则表达式匹配器:

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

And then use case V012() => ... , etc. 然后使用case V012() => ...等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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