15

我有一个使用 Scala 2.10 的项目和一个使用 Scala 2.11 的项目。它们依赖于一个可以同时编译的通用项目。

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"
)

接着

$ 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

我怎样才能让baz两个项目都使用?

4

3 回答 3

10

Yevgeniy Mordovkin 提出crossPaths := false的在 baz 项目中声明的解决方案有效。

您可能会做的另一件事是+在命令之前添加 a: sbt '+ bar/update'。这将为所有声明的 Scala 版本构建baz 。

于 2015-01-26T09:13:17.340 回答
4

我为此创建了一个SBT 插件

项目/plugins.sbt

resolvers += Resolver.sonatypeRepo("releases")

addSbtPlugin("com.lucidchart" % "sbt-cross" % "1.0")

构建.sbt

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

lazy val bar = (project in file("bar")).dependsOn(baz_2_11).settings(
  scalaVersion := "2.11.5"
)

lazy val baz = (project in file("baz")).cross

lazy val baz_2_10 = baz("2.10.4")

lazy val baz_2_11 = baz("2.11.5")

它需要多几行,但现在一切都按预期编译:sbt foo/compile工作sbt bar/compile正常。

您不必记住唯一的命令,您没有来自 的错误crossPath := false,并且与 不同++的是,这是可并行化的:sbt compile将同时编译foobarbaz正确的 Scala 版本。

于 2015-11-26T23:14:23.203 回答
0

我有一个类似的设置,并让它像这样工作:

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

和建设

sbt '++ 2.10.4 baz/compile' 'bar/compile' '++ 2.11.4 baz/compile' 'foo/compile'
于 2015-11-26T21:51:14.183 回答