Reputation: 2422
Currently in my BuildSettings.scala
file I am using crossScalaVersion := Seq("2.12.11", "2.13.2")
, and my scalaVersion := "2.13.2"
, Now when I do sbt compile, it compiles with 2.13.2
correctly without any issue. Now when I do + compile
, first it compiles with 2.12.11
, then with 2.13.2
and fails here. Now the reason why its failing with 2.13.2
on + compile
is because I have some collection libraries and some other libraries which are supported in only 2.12.11
and not in 2.13.2
, e.g if we look at this piece of code:
package com.abc.models.common.implicits
import scala.collection.TraversableLike
trait TraversableExtension {
implicit class traversableExtension[A, B](iterable: TraversableLike[A, B]) {
def headOrError(message: String): A = {
iterable.headOption.getOrElse(throw new Exception(message))
}
}
}
TraversableLike
doesn't exist anymore in 2.13.2
, also in some other files I face other issues for which classes are not supported in 2.13.2
anymore.
I can update the code according to 2.13.2
standards and support libraries, whatever is alternative to above collection etc. But then + compile
fails, i.e compilation with 2.12.11
fails, as those libraries won't exist in 2.12.11
.
How can I make it work with both the versions?
Upvotes: 1
Views: 1242
Reputation: 48430
Consider Scala-version specific source directory
├── src
│ ├── main
│ │ ├── scala
│ │ ├── scala-2.12
│ │ └── scala-2.13
in combination with CrossVersion.partialVersion
libraryDependencies :=
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 12)) => ???
case Some((2, 13)) => ???
case _ =>> ???
}
Upvotes: 4