[英]In an SBT multi project build, how to reference projects from other folders?
I am trying to tidy up my huge SBT multi-project build. 我正在尝试整理庞大的SBT多项目构建。 Currently, I have everything in one big SBT file, but I am trying to fan this out into several directories. 目前,我将所有内容都保存在一个大的SBT文件中,但是我试图将其扩展到几个目录中。
In a nutshell, this is my folder structure: 简而言之,这是我的文件夹结构:
root
+-foo
| +-foofoo
| | +-build.sbt
| +-build.sbt
| |
| +-foobar
| | +-build.sbt
| +-build.sbt
| |
| bar
| +-barfoo
| | +-build.sbt
| +-build.sbt
| |
+-build.sbt
In root/build.sbt
I have: 在root/build.sbt
我有:
lazy val root = project.
in(file(".")).
settings(publishArtifact := false).
aggregate(foo,
bar)
lazy val foo = project in file("foo")
lazy val bar = project in file("bar")
In foo/build.sbt
I have: 在foo/build.sbt
我有:
lazy val foo = project.
in(file(".")).
settings(publishArtifact := false).
aggregate(foofoo,
foobar)
lazy val foofoo = project in file("foofoo")
lazy val foobar = project in file("foobar")
In bar/build.sbt
I have: 在bar/build.sbt
我有:
lazy val bar = project.
in(file(".")).
settings(publishArtifact := false).
aggregate(barfoo)
lazy val barfoo = project in file("barfoo")
Now, I want barfoo
to depend on foofoo
, so, naïvely, I defined in barfoo/build.sbt
: 现在,我希望barfoo
依赖foofoo
,因此,我天真地在barfoo/build.sbt
定义了:
lazy val barfoo = project.in(file(".")).dependsOn(foofoo)
But when running sbt compile
it complains it can't find foofoo
. 但是在运行sbt compile
它抱怨找不到foofoo
。
So, how to correctly reference these intra-project dependencies? 那么,如何正确引用这些项目内依赖关系?
Currently the only way I can think of is to run sbt foo/publishLocal
first and then add this as libraryDependencies
. 目前,我能想到的唯一方法是先运行sbt foo/publishLocal
,然后将其添加为libraryDependencies
。 Is this the only way or is there another one? 这是唯一的方法还是还有另一种方法?
After some digging, I read that ProjectRef
should do the trick, but this gives me another error: 经过一番挖掘后,我读到ProjectRef
应该可以解决问题,但这给了我另一个错误:
I have some common dependencies in a Dependencies.scala
object in my project
subfolder. 我的project
子文件夹中的Dependencies.scala
对象中有一些常见的依赖项。 This is found by all subprojects. 所有子项目都可以找到。 However when I define: 但是当我定义时:
lazy val foofoo = ProjectRef(file("foo/foofoo"), "foofoo")
lazy val barfoo = project.in(file(".")).dependsOn(foofoo)
I get this: 我得到这个:
C:\Somewhere\bar\barfoo\build.sbt:1: error: not found: object Dependencies
import Dependencies._
^
I got it to work but I don't know if this is the right approach, so I leave it here but don't post it as an answer: 我可以使用它,但是我不知道这是否是正确的方法,因此我将其保留在此处,但不将其发布为答案:
lazy val foofoo = project in file("../../foo/foofoo")
lazy val barfoo = project.in(file(".")).dependsOn(foofoo)
Well you more or less already answered it yourself but nevertheless here is my way of doing it: 好吧,您或多或少已经亲自回答了这个问题,但是这是我的解决方法:
lazy val core = RootProject(file("../../../myCoreProject/"))
lazy val main = Project(
id = "mySubProject",
base = file(".")
).dependsOn(core)
where core
is the project I want to reference. 其中core
是我要引用的项目。 This is in the build.sbt
file of the subproject, which resides three directories further down the filetree. 该文件位于子项目的build.sbt
文件中,该文件位于文件build.sbt
方的三个目录中。
See: RootProject 另请: RootProject
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.