Reputation: 31
Is there a way that I can get different cross-scala-versions for different parts of a multi-project build? The motivation for this is that I bundle a client and server library together in one build. The client library needs to support both 2.9 and 2.10, but I'd like to use 2.10 specific libraries and features in the server.
We have a hacky workaround:
def forkSrcDirs(srcDirectory: File, scalaVer: String) = {
val ver = scalaVer.split("\\.").take(2).mkString(".")
Seq(srcDirectory / "scala-%s".format(ver), srcDirectory / "java-%s".format(ver))
}
lazy val forkSourceSettings = {
seq(
unmanagedSourceDirectories in Compile <++= (sourceDirectory in Compile, scalaVersion) apply forkSrcDirs,
unmanagedSourceDirectories in Test <++= (sourceDirectory in Test, scalaVersion) apply forkSrcDirs
)
}
which lets us achieve the goal by having all the code in server/src/main/scala-2.10, but it seems like this ought to be something that we can accomplish directly with SBT settings.
Upvotes: 3
Views: 1124
Reputation: 79
It looks like sbt-cross plugin is offering what you need. It generates a sbt project for each scala version you need from a single project definition.
In project/plugins.sbt, add
resolvers += Resolver.sonatypeRepo("releases")
addSbtPlugin("com.lucidchart" % "sbt-cross" % "1.1")
For your given structure your build.sbt should look like
lazy val root = (project in file("."))
.aggregate(server, client_2_9, client_2_10)
lazy val server = (project in file("server"))
.settings(
scalaVersion := "2.10.6"
)
lazy val client = (project in file("client"))
.cross
lazy val client_2_9 = client("2.9.3")
lazy val client_2_10 = client("2.10.6")
Upvotes: 1
Reputation: 7552
in your Build.scala:
//maybe you need to set your preferred scalaVersion
import sbt._
import Keys._
object HelloBuild extends Build {
lazy val root = Project(id = "main",
base = file(".")) aggregate(client, server)
lazy val client = Project(id = "client", base = file("client")).settings(crossScalaVersions := Seq("2.9.2", "2.10.0"))
lazy val server = Project(id = "server", base = file("server"))
}
To publish-local (remove "-local" for real publishing"):
sbt "server/publish-local" "project client" "+ publish-local"
The folder structure looks like:
.
├── client
│ └── src
│ └── main
│ └── scala
│ └── Client.scala
├── project
│ └── Build.scala
└── server
└── src
└── main
└── scala
└── Server.scala
Links:
Upvotes: 0