【问题标题】:SBT[1.1.1] Different libraryDependencies for different Scala VersionsSBT[1.1.1] 不同Scala版本的不同库依赖
【发布时间】:2018-12-06 15:27:40
【问题描述】:

我已经尝试过来自SBT cross building - choosing a different library version for different scala version 的解决方案,但是这会导致

build.sbt:27: error: No implicit for Append.Value[Seq[sbt.librarymanagement.ModuleID], sbt.Def.Initialize[sbt.librarymanagement.ModuleID]] found,
  so sbt.Def.Initialize[sbt.librarymanagement.ModuleID] cannot be appended to Seq[sbt.librarymanagement.ModuleID]
    libraryDependencies += scalaVersion(jsonDependency(_)),
                    ^
[error] sbt.compiler.EvalException: Type error in expression
[error] sbt.compiler.EvalException: Type error in expression
[error] Use 'last' for the full log.

在 sbt 1.1.1 中强制不同 Scala 版本的库依赖的正确方法是什么?

build.sbt:

libraryDependencies += scalaVersion(jsonDependency(_))

def jsonDependency(scalaVersion: String) = scalaVersion match {
  case "2.11.7" => "com.typesafe.play" %% "play-json" % "2.4.2"
  case "2.12.4" => "com.typesafe.play" %% "play-json" % "2.6.9"
}

【问题讨论】:

    标签: scala dependencies sbt


    【解决方案1】:

    第一行应该是:

    libraryDependencies += jsonDependency(scalaVersion.value)
    

    至于其余部分,它对确切的 Scala 版本号过于敏感。考虑使用CrossVersion.partialVersion 只对Scala 主版本敏感,如下:

    def jsonDependency(scalaVersion: String) =
      "com.typesafe.play" %% "play-json" %
        (CrossVersion.partialVersion(scalaVersion) match {
          case Some((2, 11)) => "2.4.2"
          case _             => "2.6.9"
        })
    

    【讨论】:

      猜你喜欢
      • 2023-04-04
      • 2019-02-25
      • 1970-01-01
      • 2020-09-08
      • 1970-01-01
      • 2020-09-26
      • 2017-09-13
      • 1970-01-01
      • 2012-05-08
      相关资源
      最近更新 更多