使用Git本地存储库作为SBT项目中的依赖项? [英] Using Git local repository as dependency in SBT project?

查看:109
本文介绍了使用Git本地存储库作为SBT项目中的依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从GitHub克隆了一个存储库到我的本地机器,将其更改为适合我的需要,现在我将在我的项目中使用它。我想我必须使用 .jar 文件。但是,没有这样的文件。



我必须自己生成它吗?

另外,我如何参考它?现在我不想将它复制到 / lib 文件夹中,因为我一直在处理克隆的项目。当我发现我必须使用这个:

 解析器+ =本地Maven仓库atfile://+ Path.userHome.absolutePath +/。m2 / repository

但是,我没有该文件 build.sbt ,我只有一个标题为 Build.scala 的普通scala文件,并且无法使用上面的代码在它里面。



另外它说 /。m2 / repository ,但它怎么知道 .jar 文件在这个存储库中?

解决方案

由于项目来自GitHub I假设它是一个git项目。解决方案是使用 RootProject 和git URI作为克隆的git项目的参考。



假设你克隆了项目到 / Users / jacek / sandbox / so / sbt-git / git-repo (就像我在可以SBT刷新git uri的依赖关系(始终或按需)?)。

执行 git log 找出你想要引用的最后一个提交,并在SBT中被引用项目的git URI中使用它 - 在 dependsOn 中。



鉴于最后一次提交是 a221379c7f82e5cc089cbf9347d473ef58255bb2 build.sbt 可能看起来像如下:

 懒惰VAL v = a221379c7f82e5cc089cbf9347d473ef58255bb2 

懒惰VAL克= RootProject(URI(S git:file:/// Users / jacek / sandbox / so / sbt-git / git-repo /#$ v))

lazy val root =文件中的项目(。) dependsOn g

也可以省略commit id并保持在用 git fetch 后面跟着 git merge 更新后的引用git项目中进行开发,如 git-pull(1)手册页

I cloned a repository from GitHub to my local machine, changed it to fit my needs and now I'm going to use it in my project. I guess I must use .jar file from it. However, there is no such a file.

Do I have to generate it myself?

Also, how do I refer to it? I don't want to copy it to /lib folder for now because I keep working on the cloned project. As I found out I have to use this:

resolvers += "Local Maven Repository" at "file://"+Path.userHome.absolutePath+"/.m2/repository" 

However, I don't have the file build.sbt, I only have file a plain scala file titled Build.scala and it's not possible to use code above in it.

Also, it says /.m2/repository, but how does it know where .jar file is in this repository?

解决方案

Since the project comes from GitHub I assume it's a git project. The solution is to use RootProject with git URI as a reference to your cloned git project.

Say you cloned the project to /Users/jacek/sandbox/so/sbt-git/git-repo (as I did in Can SBT refresh git uri dependency (always or on demand)?).

Do git log to find out the last commit you want to reference and use it in the git URI of the referenced project in SBT - in dependsOn.

Given the last commit is a221379c7f82e5cc089cbf9347d473ef58255bb2, build.sbt could look as follows:

lazy val v = "a221379c7f82e5cc089cbf9347d473ef58255bb2"

lazy val g = RootProject(uri(s"git:file:///Users/jacek/sandbox/so/sbt-git/git-repo/#$v"))

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

It's also possible to leave out the commit id and keep up with the development in the referenced git project after it's updated with git fetch followed by git merge as described in git-pull(1) Manual Page.

这篇关于使用Git本地存储库作为SBT项目中的依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆