3
votes

I have a multi project which uses two versions of Scala. The Build.scala looks like this:

import sbt._
import Keys._

object Build extends sbt.Build {
  lazy val root: Project = Project(
    id = "scalacolliderugens",
    base = file("."),
    aggregate = Seq(gen, core)
  )

  lazy val gen  = Project(...)
  lazy val core = Project(...)

  val ugenGenerator = TaskKey[Seq[File]]("ugen-generate", "Generate UGen class files")

  def runUGenGenerator(source: File, cp: Seq[File]): Seq[File] = Nil // TODO
}

Where I have a pure source generating project using Scala 2.9.2:

  lazy val gen = Project(
    id = "scalacolliderugens-gen",
    base = file("gen"),
    settings = Project.defaultSettings ++ Seq(
      scalaVersion := "2.9.2",  // !!!
      libraryDependencies ++= Seq(
        "org.scala-refactoring" % "org.scala-refactoring_2.9.1" % "0.4.1"
      ),
      libraryDependencies <+= scalaVersion { sv =>
        "org.scala-lang" % "scala-compiler" % sv
      }
    )
  )

And the actual project which incorporates the generated sources, compiling against Scala 2.10:

 lazy val core = Project(
    id = "scalacolliderugens-core",
    base = file("core"),
    settings = Project.defaultSettings ++ Seq(
      scalaVersion := "2.10.0",  // !!!
      sourceGenerators in Compile <+= (ugenGenerator in Compile),
      ugenGenerator in Compile <<=
        (scalaSource in Compile, dependencyClasspath in Runtime in gen) map {
          (src, cp) => runUGenGenerator(src, cp.files)
        }
      )
    ).dependsOn(gen)

When I compile this, I get sbt warnings:

[warn] Binary version (2.9.2) for dependency org.scala-lang#scala-library;2.9.2
[warn]  in de.sciss#scalacolliderugens_2.10;1.0.1 differs from Scala binary \
  version in project (2.10).
[info] Resolving org.scala-lang#scala-library;2.9.2 ...
[info] Done updating.
[warn] Binary version (2.9.2) for dependency org.scala-lang#scala-library;2.9.2
[warn]  in de.sciss#scalacolliderugens-gen_2.10;1.0.1 differs from Scala binary \
  version in project (2.10).
[warn] Binary version (2.9.2) for dependency org.scala-lang#scala-compiler;2.9.2
[warn]  in de.sciss#scalacolliderugens-gen_2.10;1.0.1 differs from Scala binary \
  version in project (2.10).

Should I be worried? Am I doing something bad here?

3

3 Answers

2
votes

Add the following setting to the gen project.

scalaBinaryVersion:= CrossVersion.binaryScalaVersion("2.9.2")
1
votes

OK...

I have multi-project SBT projects and they generally have SBT settings that are partly shared by all and partly specific to each sub-project. In my case the common settings include the Scala version to use.

You could structure you build specification the same way and put the Scala version setting in the sub-project-specific settings. If necessary, you could stratify the settings further if there are some settings common to all and some common to subsets of the sub-projects and other specific to each individual sub-project.

0
votes

You cannot mix bytecode from different minor versions of Scala. I.e., code compiled by any 2.9.x series compiler is not compatible with that emitted by a 2.10.x (or 2.8.x) compiler.