sbt 如何从 git 中提取依赖项?

发布于 2024-12-06 17:41:47 字数 293 浏览 1 评论 0原文

我听说(而且我知道我也见过示例,只要我记得在哪里)sbt 可以从 git 存储库获取依赖项。

我希望从 github 获取依赖项 harrah/up 。该存储库不提供任何工件 JAR 文件,仅提供使用 sbt 构建的源树。我想象的过程是 sbt 将下载源代码库,构建它,然后将其用作依赖项工件。

我可能想象 sbt 实际上可以做这样的事情。可以吗?如果是这样,怎么办?

I've heard (and I know I've seen examples too, if only I can remember where) that sbt can obtain dependencies from a git repo.

I am looking to obtain the dependency harrah/up from github. The repository does not provide any artifact JAR files, only a source tree which is set up to be built using sbt. The process that I am imagining is that sbt will download the source repo, build it, and then use that as the dependency artifact.

I may be imagining that sbt can in fact do something like this. Can it? And if so, how?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

灰色世界里的红玫瑰 2024-12-13 17:41:47

您可以使用 dependsOn 运算符将未打包的依赖项从 GitHub 导入到项目中,将其视为项目依赖项。 (这与包含预编译库依赖项的方式不同)。

请注意,您可以使用 # 表示法指定要拉取的分支。以下是一些对我来说效果很好的 Scala SBT 代码:

object V {
  val depProject = "master"
  // Other library versions
}

object Projects {
  lazy val depProject = RootProject(uri("git://github.com/me/dep-project.git#%s".format(V.depProject)))
}

// Library dependencies
lazy val myProject = Project("my-project", file("."))
.settings(myProjectSettings: _*)
.dependsOn(Projects.depProject)
.settings(
  libraryDependencies ++= Seq(...

请注意,如果您有多个依赖于同一个外部项目的 SBT 项目,则值得设置一个中央 sbt.boot.directory 以避免不必要的重新编译(请参阅此处的说明)。

You can import unpackaged dependencies into your project from GitHub by treating them as project dependencies, using the dependsOn operator. (This is distinct from the way that precompiled library dependencies are included).

Note that you can specify which branch to pull using # notation. Here's some Scala SBT code that is working well for me:

object V {
  val depProject = "master"
  // Other library versions
}

object Projects {
  lazy val depProject = RootProject(uri("git://github.com/me/dep-project.git#%s".format(V.depProject)))
}

// Library dependencies
lazy val myProject = Project("my-project", file("."))
.settings(myProjectSettings: _*)
.dependsOn(Projects.depProject)
.settings(
  libraryDependencies ++= Seq(...

Note that if you have multiple SBT projects dependending on the same external project, it's worth setting up a central sbt.boot.directory to avoid unnecessary recompilations (see instructions here).

相权↑美人 2024-12-13 17:41:47

确实是的。您可以使用 dependsOn 运算符为您的 Project 提供依赖项,并且可以通过 URI 引用 Github 项目,例如 RootProject(uri("git:/ /github.com/dragos/dupcheck.git"))。或者,您可以git clone该项目,然后使用RootProject(file(...))引用您的本地副本。有关详细信息和示例,请参阅 SBT wiki 上的“完整配置”

Yes indeed. You can give your Project a dependency with the dependsOn operator, and you can reference a Github project by its URI, for example RootProject(uri("git://github.com/dragos/dupcheck.git")). Alternatively, you can git clone the project, and then reference your local copy with RootProject(file(...)). See "Full Configuration" on the SBT wiki for details and examples.

等风来 2024-12-13 17:41:47

由于我在解决库的依赖关系时遇到问题(使用建议的 RootProject),我想指出名为 ProjectRef 的对象。因此,如果需要依赖 git 中的库,我建议按如下方式操作:

import sbt.Keys._
import sbt._

object MyBuild extends Build {

  lazy val root = Project("root", file("."))
    .dependsOn(myLibraryinGit)
    .settings(
      ...,
      libraryDependencies ++= Seq(...))

  lazy val myLibraryinGit = ProjectRef(uri("git://[email protected]:user/repo.git#branch"), "repo-name")

}

来源:http://blog.xebia.com/git-subproject-compile-time-dependencies-in-sbt/

Since I had problems getting the dependencies of my library resolved (using the suggested RootProject) I'd like to point out to the object called ProjectRef. Thus, if one need to depend on a library residing in git, I suggest to do so as follows:

import sbt.Keys._
import sbt._

object MyBuild extends Build {

  lazy val root = Project("root", file("."))
    .dependsOn(myLibraryinGit)
    .settings(
      ...,
      libraryDependencies ++= Seq(...))

  lazy val myLibraryinGit = ProjectRef(uri("git://[email protected]:user/repo.git#branch"), "repo-name")

}

Source: http://blog.xebia.com/git-subproject-compile-time-dependencies-in-sbt/

遗心遗梦遗幸福 2024-12-13 17:41:47

我想添加 sbt 0.13+ 的答案。只需将类似的内容添加到项目根文件夹中的 build.sbt 中(而不是 Build.scala):

lazy val root = (project in file(".")).dependsOn(playJongo)

lazy val playJongo = RootProject(uri("https://github.com/bekce/play-jongo.git"))

I wanted to add an answer for sbt 0.13+. Just put something like this to your build.sbt on project root folder (not Build.scala):

lazy val root = (project in file(".")).dependsOn(playJongo)

lazy val playJongo = RootProject(uri("https://github.com/bekce/play-jongo.git"))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文