Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have SBT subproject with multiple Scala versions?

I have a project using Scala 2.10 and one using Scala 2.11. They depend on a common project, which can compile with both.

lazy val foo = (project in file("foo")).dependsOn(baz).settings(
  scalaVersion := "2.10.4"
)

lazy val bar = (project in file("bar")).dependsOn(baz).settings(
  scalaVersion := "2.11.4"
)

lazy val baz = (project in file("baz")).settings(
  crossScalaVersions := Seq("2.10.4", "2.11.4"),
  scalaVersion := "2.10.4"
)

And then

$ sbt bar/update
[info] Updating {file:/home/paul/Private/test/}bar...
[info] Resolving baz#baz_2.11;0.1-SNAPSHOT ...
[warn]  module not found: baz#baz_2.11;0.1-SNAPSHOT
[warn] ==== local: tried
[warn]   /home/paul/.ivy2/local/baz/baz_2.11/0.1-SNAPSHOT/ivys/ivy.xml
[warn] ==== public: tried
[warn]   http://repo1.maven.org/maven2/baz/baz_2.11/0.1-SNAPSHOT/baz_2.11-0.1-SNAPSHOT.pom
[info] Resolving jline#jline;2.12 ...
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: baz#baz_2.11;0.1-SNAPSHOT: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[trace] Stack trace suppressed: run last bar/*:update for the full output.
[error] (bar/*:update) sbt.ResolveException: unresolved dependency: baz#baz_2.11;0.1-SNAPSHOT: not found
[error] Total time: 1 s, completed Jan 13, 2015 11:42:51 AM

How can I have baz usable by both projects?

like image 923
Paul Draper Avatar asked Jan 13 '15 18:01

Paul Draper


People also ask

Which version of Scala does sbt use?

sbt uses that same version of Scala to compile the build definitions that you write for your project because they use sbt APIs. This version of Scala is fixed for a specific sbt release and cannot be changed. For sbt 1.7. 1, this version is Scala 2.12.

What is ThisBuild in sbt?

Typically, if a key has no associated value in a more-specific scope, sbt will try to get a value from a more general scope, such as the ThisBuild scope. This feature allows you to set a value once in a more general scope, allowing multiple more-specific scopes to inherit the value.

Is sbt same as Scala?

sbt is the de facto build tool in the Scala community, used by the Lift web framework and Play Framework. Scala's commercial outlet, Lightbend Inc., has called sbt "arguably the best tool for building Scala projects", saying that its two most prominent features are incremental compilation and an interactive shell.


1 Answers

Yevgeniy Mordovkin's proposed solution, to declare crossPaths := false in the baz project, works.

Another thing you might do, is to prepend a + before the command: sbt '+ bar/update'. That will build baz for all declared Scala versions.

like image 196
Ionuț G. Stan Avatar answered Oct 23 '22 23:10

Ionuț G. Stan