Pieter van Lill
Pieter van Lill

Reputation: 33

SBT[1.1.1] Different libraryDependencies for different Scala Versions

I have tried the solution from: SBT cross building - choosing a different library version for different scala version however this results in

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.

What is the correct way of forcing library dependencies for different Scala versions in sbt 1.1.1?

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

Upvotes: 1

Views: 458

Answers (1)

Seth Tisue
Seth Tisue

Reputation: 30508

The first line should be:

libraryDependencies += jsonDependency(scalaVersion.value)

As for the rest, it's unnecessarily sensitive to exact Scala version numbers. Consider using CrossVersion.partialVersion to be sensitive to the Scala major version only, as follows:

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

Upvotes: 1

Related Questions