【发布时间】:2017-05-07 13:52:49
【问题描述】:
我正在尝试像这样设置多项目构建:
+-- common
| +-- build.sbt
+-- api
| +-- build.sbt
+-- indexer
| +-- build.sbt
+-- build.sbt
build.sbt 在 root 中看起来像这样:
lazy val common = (project in file("common"))
lazy val searchApi = (project in file("search"))
.dependsOn(common)
lazy val indexer = (project in file("indexer"))
.dependsOn(common)
如您所见,indexer 和 api 都依赖于 common,但不相互依赖。问题是,如果我尝试为某个任务执行触发式执行,比如compile:
sbt ~api/compile
然后更改 indexer 项目中的文件,即使更改的文件实际上不在其类路径中,该项目仍将重新编译 - 似乎 watchSources 始终包含根 @987654331 引用的每个项目@ 并且不会考虑您实际运行任务的项目。
我尝试过滤watchSources,但很难做到整洁,因为我放入的build.sbt 文件只能看到它所在项目的资源......例如watchSources in indexer/build.sbt 只能看到indexer 里面的观看源,build.sbt 在根目录下只能看src/main/resources 在根目录下(看不到子项目的watchSources) .
有没有人有解决这个问题的好方法。我所拥有的最好的就是在每个子项目的build.sbt...
watchSources <<= (watchSources) map { files =>
if (Option(System.getProperty("project")).getOrElse("none").equals("indexer")) {
files
} else {
Nil
}
}
...然后运行sbt -Dproject=indexer ~indexer/compile。
【问题讨论】: