我正在为如何crossScalaVersions
处理子项目而苦苦挣扎。
我有一个使用 2.10 (foo) 编译的项目和一个使用 2.11 (bar) 编译的项目。他们共享一个交叉编译的项目(常见)。
如何编译项目 foo 和 bar?
构建.sbt
lazy val root = (project in file(".")).aggregate(foo, bar).settings(
crossScalaVersions := Seq("2.10.4", "2.11.4")
)
lazy val foo = (project in file("foo")).dependsOn(common).settings(
crossScalaVersions := Seq("2.10.4"),
scalaVersion := "2.10.4"
)
lazy val bar = (project in file("bar")).dependsOn(common).settings(
crossScalaVersions := Seq("2.11.4"),
scalaVersion := "2.11.4"
)
lazy val common = (project in file("common")).settings(
crossScalaVersions := Seq("2.10.4", "2.11.4")
)
项目/build.properties
sbt.version=0.13.7
foo/src/main/scala/Foo.scala
object Foo {
<xml>{new C}</xml>
}
bar/src/main/scala/Bar.scala
case class Bar(a: C, b: C, c: C, d: C, e: C, f: C, g: C,
h: C, i: C, j: C, k: C, l: C, m: C, n: C, o: C, p: C,
q: C, r: C, s: C, t: C, u: C, v: C, w: C, x: C, y: C,
z: C)
common/src/main/scala/Common.scala
class C {}
尝试 1
$ sbt compile
[info] Resolving jline#jline;2.12 ...
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: common#common_2.11;0.1-SNAPSHOT: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn] Note: Unresolved dependencies path:
[warn] common:common_2.11:0.1-SNAPSHOT
[warn] +- bar:bar_2.11:0.1-SNAPSHOT
sbt.ResolveException: unresolved dependency: common#common_2.11;0.1-SNAPSHOT: not found
尝试 2
$ sbt +compile
[error] /home/paul/test/bar/src/main/scala/Bar.scala:1: Implementation restriction: case classes cannot have more than 22 parameters.
[error] case class Bar(a: C, b: C, c: C, d: C, e: C, f: C, g: C,
[error] ^
[error] one error found
[error] (bar/compile:compile) Compilation failed
尝试 3
$ sbt foo/compile bar/compile
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: common#common_2.11;0.1-SNAPSHOT: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn] Note: Unresolved dependencies path:
[warn] common:common_2.11:0.1-SNAPSHOT
[warn] +- bar:bar_2.11:0.1-SNAPSHOT
sbt.ResolveException: unresolved dependency: common#common_2.11;0.1-SNAPSHOT: not found
尝试 4
$ sbt +foo/compile +bar/compile
[error] /home/paul/test3/foo/src/main/scala/Foo.scala:2: To compile XML syntax, the scala.xml package must be on the classpath.
[error] Please see http://docs.scala-lang.org/overviews/core/scala-2.11.html#scala-xml.
[error] <xml>{new C}</xml>
[error] ^
[error] one error found
[error] (foo/compile:compile) Compilation failed
尝试 5
我什至尝试使用相同的基本目录但不同的 scala 版本定义common_2_10
和项目。common_2_11
我记得读过目标是由 Scala 版本命名的,但 SBT 说存在冲突。
$ sbt
[error] Overlapping output directories:/home/paul/test3/common/target:
[error] ProjectRef(file:/home/paul/test3/,common_2_10)
[error] ProjectRef(file:/home/paul/test3/,common_2_11)
我唯一要做的就是手动指定版本:
$ sbt ++2.10.4 foo/compile ++2.11.4 bar/compile
但是这是很多命令,永远不能使用并行性,并且避免了(1)项目聚合和(2)交叉构建的整个使用。
我是否遗漏了一些关于 意图的基本内容crossScalaVersions
?或者有没有办法让它与 SBT 的其余部分配合得很好,并让我编译我的异构项目?