3

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?

0__
  • 66,707
  • 21
  • 171
  • 266

3 Answers3

2

Add the following setting to the gen project.

scalaBinaryVersion:= CrossVersion.binaryScalaVersion("2.9.2")
  • 3
    Do you have any further links explaining what this does/implies? Would that prevent `-SNAPSHOT` versions to intrude? – 0__ May 03 '13 at 12:15
1

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.

Randall Schulz
  • 26,420
  • 4
  • 61
  • 81
  • Yes, I did exactly that (see my question -- `scalaVersion` is in the sub-project settings). That's why I don't understand the sbt warnings. My reading is that it assumes some implicit `scalaVersion in ThisBuild` and gets worried about the discrepancy, even if the sub-projects are not binarily combined. – 0__ Feb 07 '13 at 18:02
0

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.

Randall Schulz
  • 26,420
  • 4
  • 61
  • 81
  • I know... My project is Scala 2.10, _except_ for a __source code generator__ sub-project which runs (like sbt, by the way) using Scala 2.9.2. That generator emits legal source code compilable both in Scala 2.9 and 2.10. – 0__ Feb 07 '13 at 15:47