sbt 如何从 git 中提取依赖项?
我听说(而且我知道我也见过示例,只要我记得在哪里)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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用
dependsOn
运算符将未打包的依赖项从 GitHub 导入到项目中,将其视为项目依赖项。 (这与包含预编译库依赖项的方式不同)。请注意,您可以使用
#
表示法指定要拉取的分支。以下是一些对我来说效果很好的 Scala SBT 代码:请注意,如果您有多个依赖于同一个外部项目的 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: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).确实是的。您可以使用
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 thedependsOn
operator, and you can reference a Github project by its URI, for exampleRootProject(uri("git://github.com/dragos/dupcheck.git"))
. Alternatively, you cangit clone
the project, and then reference your local copy withRootProject(file(...))
. See "Full Configuration" on the SBT wiki for details and examples.由于我在解决库的依赖关系时遇到问题(使用建议的
RootProject
),我想指出名为ProjectRef
的对象。因此,如果需要依赖 git 中的库,我建议按如下方式操作:来源: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 calledProjectRef
. Thus, if one need to depend on a library residing in git, I suggest to do so as follows:Source: http://blog.xebia.com/git-subproject-compile-time-dependencies-in-sbt/
我想添加 sbt 0.13+ 的答案。只需将类似的内容添加到项目根文件夹中的
build.sbt
中(而不是Build.scala
):I wanted to add an answer for sbt 0.13+. Just put something like this to your
build.sbt
on project root folder (notBuild.scala
):