clojure 和 leiningen - 使用 git 存储库作为依赖项

发布于 2024-12-29 17:52:37 字数 320 浏览 1 评论 0 原文

是否可以让 leiningen 直接从 git 存储库(在 github 上)拉取项目作为依赖项?

将 Bundler 与 Ruby 结合使用,可以将 gem 映射到 git 存储库,从而实现依赖项目的快速开发和集成。

更新

根据已接受的答案,现在有一个用于管理 git-deps 的 leiningen 插件: https://github.com/tobyhede/lein-git-deps

Is it possible to have leiningen pull a project directly from a git repository (on github) as a dependency?

Using Bundler with Ruby, it is possible to map a gem to a git repo, allowing for rapid development and integration of dependent projects.

Update

Based on the accepted answer, there is now a leiningen plugin for managing git-deps:
https://github.com/tobyhede/lein-git-deps

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

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

发布评论

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

评论(4

你是年少的欢喜 2025-01-05 17:52:37

我刚刚在 clojurescriptone 的 project.clj 中找到了这个,

我认为这可能对您有帮助:

:git-dependencies [["https://github.com/clojure/clojurescript.git"
                       "886d8dc81812962d30a741d6d05ce9d90975160f"]
                   ["https://github.com/levand/domina.git"
                       "8933b2d12c44832c9bfaecf457a1bc5db251a774"]]

该文件是 这里

I just found this in clojurescriptone's project.clj

I think it maybe helpful to you:

:git-dependencies [["https://github.com/clojure/clojurescript.git"
                       "886d8dc81812962d30a741d6d05ce9d90975160f"]
                   ["https://github.com/levand/domina.git"
                       "8933b2d12c44832c9bfaecf457a1bc5db251a774"]]

The file is here.

£烟消云散 2025-01-05 17:52:37

Leiningen 不会为你拉动(编辑:无论如何,不​​是开箱即用的;按照 Sunng 的答案的引导,人们会发现已经为此编写了一个插件 - 另请参阅我对该答案的评论;签出依赖仍然是一个很好的内置解决方案),但您可以将其他项目的签出放在类路径上。自述文件的常见问题解答部分描述了此功能;以下是相关问答:

问:我想并行破解两个项目,但这很烦人
在它们之间切换。
A:如果您在中创建一个名为checkouts的目录
您的项目根目录并将其他一些项目根目录符号链接到其中,
莱宁根将允许你并行地攻击它们。这意味着
依赖项的更改将在主项目中可见,无需
必须经历整个过程
install/switch-projects/deps/restart-repl 循环,并将其复制到
checkouts 将优先于中声明的依赖项
项目.clj。请注意,这并不能替代列出
项目位于:依赖项;它只是为了方便起见补充。

Leiningen won't do the pulling for you (edit: not out of the box, anyway; following the lead from Sunng's answer leads one to discover that a plugin has been written for this -- see also my comment on that answer; checkout deps remain a good, built-in solution), but you can have checkouts of other projects put on the classpath. This functionality is described in the FAQ section of the README; here's the relevant Q&A:

Q: I want to hack two projects in parallel, but it's annoying to
switch between them.
A: If you create a directory called checkouts in
your project root and symlink some other project roots into it,
Leiningen will allow you to hack on them in parallel. That means
changes in the dependency will be visible in the main project without
having to go through the whole
install/switch-projects/deps/restart-repl cycle, and the copy in
checkouts will take precedence over the dependency declared in
project.clj. Note that this is not a replacement for listing the
project in :dependencies; it simply supplements that for convenience.

记忆之渊 2025-01-05 17:52:37

2017 年的答案:使用 lein-voom

您可以使用 < a href="https://github.com/LonoCloud/lein-voom/" rel="nofollow noreferrer">lein-voom 来拉取和构建项目来自 GitHub 或其他 Git 存储库的依赖项。它的工作原理是让您使用特定于 voom 的元数据来注释依赖向量对条目。以下是自述文件中的一个示例:

^{:voom {:repo "https://github.com/ring-clojure/ring" :branch "1.3"}}
[ring/ring-core "1.3.0-RC1-20140519_142204-gaf0379b"]

voom 给出的主要用例是允许在单独的 Git 存储库中维护多个 Clojure 项目的团队轻松依赖另一个项目的一个或多个项目的当前版本,而无需必须不断部署开发快照版本。

我更喜欢 lein-voom 而不是 lein-git-deps (2012 年之前接受的答案中推荐的插件),原因如下:

  1. 事实是通过元数据给出的规范使该插件更加灵活且易于扩展。它已经有一个用于指定存储库的特定分支/标签的选项。您可以将其他键/值对添加到映射中,以进行额外的细粒度控制,而无需太多工作。

  2. 您可以简单地从稳定版本的依赖条目中删除元数据;即,一旦您的依赖项从 GitHub 转移到 Clojars,就无需移动条目/重构您的 project.clj

  3. 在撰写本文时(2017 年 11 月),lein-voom 在过去几个月中进行了更新,而 lein-git-deps 已经停滞了4 年。

Answer for 2017: Use lein-voom

You can use lein-voom to pull and build project dependencies from GitHub or other Git repositories. It works by letting you annotate your dependence vector-pair entries with voom-specific meta data. Here's an example from the README:

^{:voom {:repo "https://github.com/ring-clojure/ring" :branch "1.3"}}
[ring/ring-core "1.3.0-RC1-20140519_142204-gaf0379b"]

The main use case given for voom is allowing teams that maintain multiple Clojure projects in separate Git repositories to easily depend on the current version of one or more of the projects from another without having to constantly deploy development snapshot releases.

I prefer lein-voom over lein-git-deps (the plugin recommended in the previously-accepted answer from 2012) for a few reasons:

  1. The fact that the specification is given through meta-data makes this plugin more flexible and easily extensible. It already has an option for specifying a specific branch/tag of the repository. You could add other key/value pairs to the map for additional fine-grained control without too much work.

  2. You can simply delete the meta-data from your dependence entry for stable releases; i.e., there's no need to move entries around / refactor your project.clj once your dependence moves from GitHub into Clojars.

  3. At the time of writing (November 2017), lein-voom has been updated in the past couple of months, whereas lein-git-deps has been stagnant for 4 years.

不打扰别人 2025-01-05 17:52:37

我刚刚使用 deps.edn 文件中>lein-tools-deps。您仍然可以使用 Leiningen 作为构建工具并使用插件。但是您可以使用 deps.edn 提取 git 依赖项(以及所有其他依赖项)。

您的 project.clj 看起来像这样:

(defproject example-project "0.1.0-SNAPSHOT"
  :source-paths           [] ;; provided by lein-tools-deps
  :resource-paths         [] ;; provided by lein-tools-deps
  :min-lein-version       "2.0.0"
  :main                   example.core
  :aot                    [example]
  :jar-name               "example.jar"
  :plugins                [[lein-tools-deps "0.4.5"]]
  :middleware             [lein-tools-deps.plugin/resolve-dependencies-with-deps-edn]
  :lein-tools-deps/config {:config-files [:install :project]})

然后您的 deps.edn 也在项目根目录上,看起来像这样:

{:paths ["src" "resources"]
 :deps {org.clojure/clojure    {:mvn/version "1.10.1"}
        org.clojure/data.json  {:mvn/version "1.1.0"}
        github/repo            {:git/url "https://github.com/github/repo.git"
                                :sha "e5f5c9e6839191f1e37ddfa51cf442b2d5403ff3"}}}

I just moved my deps out of Leiningen and into a deps.edn file using lein-tools-deps. You can still use Leiningen as your build tool and use the plugins. But you can pull git dependencies (and all your other dependencies) using deps.edn.

Your project.clj looks something like this:

(defproject example-project "0.1.0-SNAPSHOT"
  :source-paths           [] ;; provided by lein-tools-deps
  :resource-paths         [] ;; provided by lein-tools-deps
  :min-lein-version       "2.0.0"
  :main                   example.core
  :aot                    [example]
  :jar-name               "example.jar"
  :plugins                [[lein-tools-deps "0.4.5"]]
  :middleware             [lein-tools-deps.plugin/resolve-dependencies-with-deps-edn]
  :lein-tools-deps/config {:config-files [:install :project]})

and then your deps.edn is also on the project root and looks something like this:

{:paths ["src" "resources"]
 :deps {org.clojure/clojure    {:mvn/version "1.10.1"}
        org.clojure/data.json  {:mvn/version "1.1.0"}
        github/repo            {:git/url "https://github.com/github/repo.git"
                                :sha "e5f5c9e6839191f1e37ddfa51cf442b2d5403ff3"}}}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文