如何指定必须先构建另一个项目

如何指定必须先构建另一个项目

本文介绍了如何指定必须先构建另一个项目 B 才能构建项目 A?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我公司的一个人有一个名为 commons 的 sbt 项目,该项目非常通用.这个项目是用传统的 sbt 方式定义的:在 project/Build.scala 文件中构建定义的主文件夹中.

Suppose one guy in my company has an sbt project called commons that's pretty general-purpose. This project is defined in the traditional sbt way: in the main folder with the build definition in project/Build.scala file.

现在其他人正在开发一个名为 databinding 的项目,该项目依赖于 commons.我们想以同样的方式定义这个项目,使用 project/Build.scala.

Now some other guy is developing a project called databinding that depends on commons. We want to define this project in the same way, with project/Build.scala.

我们有以下目录布局:

dev/
  commons/
    src/
      *.scala files here...
    project/
      Build.scala
  databinding/
    src/
      *.scala files here...
    project/
      Build.scala

如何指定 databinding 需要先构建 commons 并使用输出类文件?

How can I specify that databinding requires commons to be built first and use the output class files?

我阅读了多项目构建,然后来到databinding 的构建定义如下:

I read Multi-project builds, and came up with the following for the build definition of databinding:

object MyBuild extends Build {

  lazy val root = Project(id = "databinding", base = file(".")) settings (
    // ... omitted
  ) dependsOn (commons)

  lazy val common = Project(id = "commons",
    base = file("../commons")
  )

}

除非它不起作用:sbt 不喜欢 .. 并抛出 AssertionError.显然,commons 应该是 databinding 里面的一个文件夹.但是这两个项目保存在单独的 git 存储库中,我们不能嵌套.

Except it doesn't work: sbt doesn't like the .. and throws an AssertionError. Apparently, commons should be a folder inside databinding. But these two projects are kept in separate git repositories, which we cannot nest.

如何正确指定此依赖项?

How can this dependency be specified properly?

推荐答案

您需要在将在 dev/project 中定义的根项目中定义多项目(或任何名称,但这个名称适合)/Build.scala.

object RootBuild extends Build {
  lazy val root = Project(id = "root", base = file("."))
    .settings(...)
    .aggregate(commons, databinding)

  lazy val commons = Project(id = "commons", base = file("commons"))
    .settings(...)

  lazy val databinding = Project(id = "databinding", base = file("databinding"))
    .settings(...)
    .dependsOn(commons)
}

还有一点,SBT 不支持子项目中的 *.scala 配置文件.这意味着您必须将您在 commons/project/Build.scaladatabinding/project/Build.scala 上所做的配置分别迁移到 commons/build.sbtdatabinding/build.sbt.

one more thing, SBT doesn't support *.scala configuration files in sub-projects. This means that you will have to migrate the configuration you made on commons/project/Build.scala and databinding/project/Build.scala into respectively commons/build.sbt and databinding/build.sbt.

如果您的某些配置不适合 .sbt 定义文件,则必须将它们添加到根 project/Build.scala 中.显然,在根 Build.scala 中定义的设置在 *.sbt 文件中可用.

If some of your configuration are not suitable for a .sbt definition file, you will have to add them in the root project/Build.scala. Obviously, settings defined in root Build.scala are available in *.sbt files.

这篇关于如何指定必须先构建另一个项目 B 才能构建项目 A?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 12:53