How to have different source code when cross-compiling Scala with sbt? (changes to MurmurHash)

I use SBT 0.13.2 (it can also be, for example, 0.13.5), and try to take a project written for 2.10 and cross-compile it for both 2.9 and 2.10. He uses scala.util.hashing.MurmurHash3, which is not in 2.9; instead there scala.util.MurmurHash(what might be incompatible ???). My source must be different in order to handle imports in different places and different interfaces. I assume that I need to have two different files .scalaand somehow tell SBT to compile one file .scalawhen compiling for 2.9 and another file .scalafor 2.10. How to do it?

Thank.

+4
source share
1 answer

You can add to unmanagedSourceDirectories:

lazy val commonSettings = Seq(
  scalaVersion := "2.10.4",
  unmanagedSourceDirectories in Compile +=
    (sourceDirectory in Compile).value / ("scala_" + (scalaBinaryVersion.value match {
      case v if v startsWith "2.9." => "2.9"
      case v => v
    }))
)

lazy val root = (project in file(".")).
  aggregate(app).
  settings(commonSettings: _*)

lazy val app = (project in file("app")).
  settings(commonSettings: _*)

Now it src/main/scala_2.10is part of the source directory for Scala 2.10.x and src/main/scala_2.9for Scala 2.9.x.

Update

Now the port request opened by @indrajitr Enable cross-version support for Scala sources. # 1799

+1
source

Source: https://habr.com/ru/post/1569371/


All Articles