这是我的项目结构,
root/build.sbt
a/build.sbt
b/build.sbt
c/c1/build.sbt
c/c2/build.sbt
...
我想要实现的是不需要像
那样在root/build.sbt
中定义每个项目
lazy val a = project
lazy val b = project
lazy val c1 = (project in file("c/c1"))
lazy val c2 = (project in file("c/c2"))
lazy val root = (project in file(".").aggregate(a,b,c1,c2)
我尝试过的是
lazy val subprojects = (file(".") * DirectoryFilter).get
.filter(dir => (dir / "build.sbt").exists)
.map(dir => Project(dir.getName, dir).settings(name:=dir.getName).settings(commonSettings: _*))
lazy val root = (project in file("."))
// the following line does not work
//.aggregate(subprojects.map(p => p: ProjectReference): _*)
但是有错误堆栈,
[info] Loading settings for project root from build.sbt ...
[error] java.lang.RuntimeException: No project 'a' in 'file:/xxx/root/'.
[error] Valid project IDs: root
[error] at scala.sys.package$.error(package.scala:27)
[error] at sbt.internal.Load$.$anonfun$checkAll$3(Load.scala:606)
[error] at sbt.internal.Load$.$anonfun$checkAll$3$adapted(Load.scala:600)
[error] at scala.collection.immutable.List.foreach(List.scala:389)
[error] at sbt.internal.Load$.$anonfun$checkAll$2(Load.scala:600)
[error] at sbt.internal.Load$.$anonfun$checkAll$2$adapted(Load.scala:600)
[error] at scala.collection.TraversableLike$WithFilter.$anonfun$foreach$1(TraversableLike.scala:789)
[error] at scala.collection.immutable.Map$Map1.foreach(Map.scala:125)
[error] at scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:788)
[error] at sbt.internal.Load$.checkAll(Load.scala:600)
[error] at sbt.internal.Load$.loadURI(Load.scala:493)
[error] at sbt.internal.Load$.load(Load.scala:471)
[error] at sbt.internal.Load$.$anonfun$apply$1(Load.scala:251)
[error] at sbt.internal.Load$.timed(Load.scala:1395)
[error] at sbt.internal.Load$.apply(Load.scala:251)
[error] at sbt.internal.Load$.defaultLoad(Load.scala:69)
[error] at sbt.BuiltinCommands$.liftedTree1$1(Main.scala:829)
[error] at sbt.BuiltinCommands$.doLoadProject(Main.scala:829)
[error] at sbt.BuiltinCommands$.$anonfun$loadProjectImpl$2(Main.scala:800)
[error] at sbt.Command$.$anonfun$applyEffect$4(Command.scala:142)
[error] at sbt.Command$.$anonfun$applyEffect$2(Command.scala:137)
[error] at sbt.Command$.process(Command.scala:181)
[error] at sbt.MainLoop$.processCommand(MainLoop.scala:151)
[error] at sbt.MainLoop$.$anonfun$next$2(MainLoop.scala:139)
[error] at sbt.State$$anon$1.runCmd$1(State.scala:246)
[error] at sbt.State$$anon$1.process(State.scala:250)
[error] at sbt.MainLoop$.$anonfun$next$1(MainLoop.scala:139)
[error] at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error] at sbt.MainLoop$.next(MainLoop.scala:139)
[error] at sbt.MainLoop$.run(MainLoop.scala:132)
[error] at sbt.MainLoop$.$anonfun$runWithNewLog$1(MainLoop.scala:110)
[error] at sbt.io.Using.apply(Using.scala:22)
[error] at sbt.MainLoop$.runWithNewLog(MainLoop.scala:104)
[error] at sbt.MainLoop$.runAndClearLast(MainLoop.scala:59)
[error] at sbt.MainLoop$.runLoggedLoop(MainLoop.scala:44)
[error] at sbt.MainLoop$.runLogged(MainLoop.scala:35)
[error] at sbt.StandardMain$.runManaged(Main.scala:138)
[error] at sbt.xMain.run(Main.scala:89)
[error] at xsbt.boot.Launch$$anonfun$run$1.apply(Launch.scala:109)
[error] at xsbt.boot.Launch$.withContextLoader(Launch.scala:128)
[error] at xsbt.boot.Launch$.run(Launch.scala:109)
[error] at xsbt.boot.Launch$$anonfun$apply$1.apply(Launch.scala:35)
[error] at xsbt.boot.Launch$.launch(Launch.scala:117)
[error] at xsbt.boot.Launch$.apply(Launch.scala:18)
[error] at xsbt.boot.Boot$.runImpl(Boot.scala:41)
[error] at xsbt.boot.Boot$.main(Boot.scala:17)
[error] at xsbt.boot.Boot.main(Boot.scala)
[error] No project 'a' in 'file:/xxx/root/'.
[error] Valid project IDs: root
这看起来像是问题Ability to programmatically define projects: Seq[Project],文档Multi-project builds似乎暗示它不受支持。有办法吗?还是违反最佳做法?