我有一个使用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
使用?
答案 0 :(得分:7)
Yevgeniy Mordovkin建议的解决方案,在baz项目中声明crossPaths := false
,可行。
您可能会做的另一件事是在命令前添加+
:sbt '+ bar/update'
。这将为所有声明的Scala版本构建 baz 。
答案 1 :(得分:2)
我为此创建了SBT plugin。
<强>项目/ plugins.sbt 强>
resolvers += Resolver.sonatypeRepo("releases")
addSbtPlugin("com.lucidchart" % "sbt-cross" % "1.0")
<强> build.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")
它需要更多行,但现在所有内容都按预期编译:{{1}}有效,sbt foo/compile
有效。
您不必记住唯一命令,您没有来自sbt bar/compile
的错误,与crossPath := false
不同,这是可并行化的:++
将编译sbt compile
,foo
和bar
同时使用正确的Scala版本。
答案 2 :(得分: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'