-1

我有一个在 scala 2.13.1 上构建的 sbt Scala 项目我想用 scala-2.12.8 构建它,因为在做了一些研究之后,一些库依赖项仅支持 scala 2.12这个问题正是我的用例我遵循了答案但我我收到一个错误

error] scala.MatchError: Some((2,13)) (of class scala.Some)
[error]     at $97a4428383eb69f53d6e$.$anonfun$$sbtdef$1(/home/sara/git/gitinterpret/interpret/build.sbt:56)
[error]     at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error]     at sbt.internal.util.EvaluateSettings$MixedNode.evaluate0(INode.scala:221)
[error]     at sbt.internal.util.EvaluateSettings$INode.evaluate(INode.scala:164)
[error]     at sbt.internal.util.EvaluateSettings.$anonfun$submitEvaluate$1(INode.scala:87)
[error]     at sbt.internal.util.EvaluateSettings.sbt$internal$util$EvaluateSettings$$run0(INode.scala:98)
[error]     at sbt.internal.util.EvaluateSettings$$anon$3.run(INode.scala:94)
[error]     at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[error]     at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[error]     at java.base/java.lang.Thread.run(Thread.java:834)
[error] scala.MatchError: Some((2,13)) (of class scala.Some)
[error] Use 'last' for the full log.
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? 

这是我的 build.sbt

lazy val scala212 = "2.12.8"

lazy val scala213 = "2.13.1"

scalaVersion := scala213

lazy val supportedScalaVersions = List(scala213, scala212)

lazy val root = (project in file("."))
  .settings(
    crossScalaVersions := supportedScalaVersions,
  )

libraryDependencies := { CrossVersion.partialVersion(scalaVersion.value) match {
  case Some((2,scalaMajor)) if scalaMajor == 12.8 =>
   libraryDependencies.value ++ Seq(
      "org.scala-lang" % "scala-library" % "2.12.8",
      "org.mongodb.scala" %% "mongo-scala-driver" % "2.8.0"
  "io.gatling.highcharts" % "gatling-charts-highcharts" % "3.3.1" % "test"
  case Some((2,scalaMajor)) if scalaMajor == 13.1 =>
    libraryDependencies.value ++ Seq(
      "org.scala-lang" % "scala-library" % "2.13.1",
      "org.mongodb.scala" %% "mongo-scala-driver" % "2.8.0",
      "com.typesafe.akka" %% "akka-actor" % "2.6.3",
    )
}
}
4

1 回答 1

3

例如 2.13.1 的版本控制模式是

MAJOR.MINOR.PATCH
  2    13   1

CrossVersion.partialVersion返回表示 (MAJOR, MINOR) 的元组。因此尝试

CrossVersion.partialVersion(scalaVersion.value) match {
  case Some((2, 12)) => ???
  case Some((2, 13)) => ???
  case _ =>> ???
}

解决评论,如果您想获得补丁版本,请尝试使用正则表达式

val VersionSchema = """(\d+)\.(\d+)\.(\d+)""".r
scalaVersion.value match {
  case VersionSchema("2", "13", "1") => ???
  case VersionSchema("2", "12", "8") => ???
  case _ => ???
}

但是没有必要这样做,因为补丁版本之间不应该有重大更改。

于 2020-04-01T11:43:44.107 回答