在SBT中使用ProjectRef进行多项目构建时,不能“投射gostats”吗?

时间:2014-01-10 09:40:36

标签: sbt

我有以下Build项目定义,用于设置多项目构建:

import sbt._
import Keys._

object Build extends Build {
  lazy val gostats = ProjectRef(id = "gostats", base = file("modules/gostats_0.1"))

  lazy val godeploy = Project(id = "godeploy", base = file("."))
    .aggregate(gostats).dependsOn(gostats)
}

这编译得很好,但我无法在SBT控制台中运行project gostats

如果我将ProjectRef更改为Project gostats,则gostats不再编译,因为在这种情况下SBT会忽略我的项目设置。

我怎样才能充分利用两个世界?

1 个答案:

答案 0 :(得分:2)

如果您使用SBT 0.13.x,则可以在build.sbt中定义Multi-Project Builds。这是在您的对象godeploy之后定义gostatsBuild的方法。

lazy val godeploy = project in file(".") aggregate gostats dependsOn gostats

lazy val gostats = project in file("modules") / "gostats_0.1"

有了这个,我可以project没有错误的项目。

[godeploy]> projects
[info] In file:/Users/jacek/sandbox/so/multi-0.13.1-project-ref/
[info]   * godeploy
[info]     gostats
[godeploy]> project gostats
[info] Set current project to gostats (in build file:/Users/jacek/sandbox/so/multi-0.13.1-project-ref/)
[gostats]> projects
[info] In file:/Users/jacek/sandbox/so/multi-0.13.1-project-ref/
[info]     godeploy
[info]   * gostats
[gostats]> compile
[info] Updating {file:/Users/jacek/sandbox/so/multi-0.13.1-project-ref/}gostats...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[success] Total time: 0 s, completed Jan 11, 2014 2:23:34 PM

SBT还为我创建了项目目录结构,因为我只从build.sbtproject/build.properties文件开始。

jacek:~/sandbox/so/multi-0.13.1-project-ref
$ tree -L 2
.
├── build.sbt
├── modules
│   └── gostats_0.1
└── project
    └── build.properties

3 directories, 2 files