sbt 如何从 git 中提取依赖项?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7550376/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can sbt pull dependency artifacts from git?
提问by Owen
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.
我听说过(我知道我也看过例子,如果我能记得在哪里)sbt
可以从 git repo 获取依赖项。
I am looking to obtain the dependency harrah/upfrom 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.
我希望从 github获取依赖项harrah/up。该存储库不提供任何工件 JAR 文件,仅提供一个使用sbt
. 我想象的过程是sbt
下载源代码库,构建它,然后将其用作依赖项工件。
I may be imagining that sbt
can in fact do something like this. Can it? And if so, how?
我可能在想象它sbt
实际上可以做这样的事情。它可以?如果是这样,如何?
采纳答案by Kipton Barros
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.
确实是的。您可以为操作符Project
提供依赖项dependsOn
,并且您可以通过其 URI 引用 Github 项目,例如RootProject(uri("git://github.com/dragos/dupcheck.git"))
. 或者,您可以创建git clone
项目,然后使用RootProject(file(...))
. 有关详细信息和示例,请参阅SBT wiki 上的“完整配置”。
回答by Alex Dean
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).
您可以使用dependsOn
运算符将未打包的依赖项从 GitHub 导入到您的项目中,方法是将它们视为项目依赖项。(这与包含预编译库依赖项的方式不同)。
Note that you can specify which branch to pull using #
notation. Here's some Scala SBT code that is working well for me:
请注意,您可以使用#
符号指定要拉取的分支。这是一些对我来说效果很好的 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(...
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).
请注意,如果您有多个 SBT 项目依赖于同一个外部项目,则值得设置一个中心sbt.boot.directory
以避免不必要的重新编译(请参阅此处的说明)。
回答by Marc Juchli
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:
由于我在解决库的依赖项时遇到问题(使用建议的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")
}
Source: http://blog.xebia.com/git-subproject-compile-time-dependencies-in-sbt/
来源:http: //blog.xebia.com/git-subproject-compile-time-dependencies-in-sbt/
回答by bekce
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
):
我想为 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"))