gpt4 book ai didi

ruby-on-rails - 如何在 gemspec 文件中指定依赖 gem 的路径?

转载 作者:行者123 更新时间:2023-12-04 03:22:32 24 4
gpt4 key购买 nike

我创建了一个 gem(X) 并且它没有发布。现在我正在创建另一个 gem,它将 gem X 添加为这样的依赖项:-

s.add_dependency "X"

在 gemspec 文件中。

由于 gem(X) 不在 ruby​​gem 或 git 或 ruby​​forge 上,因此 bundle install 命令会引发错误:

could not find the gem X**



我认为为 X 指定路径可以解决问题,但是如何呢?

最佳答案

我想我看到了@bor1s 在关于 git 引用的 SO 帖子中所指的内容。
gemspec文件是关于发布 gem 的依赖项。您的 Gemfile设置您的本地开发环境,通常通过调用 gemspec .

在您的情况下,您的 gemspec应该有这个

s.add_dependency "X"

然后是您的 Gemfile看起来像这样(确保本地引用在 gemspec 调用之后):
source "http://www.rubygems.org"
gemspec
gem "X", :path => "/Users/vikram/source/X"

引自 Yahuda Katz 的 blog post about gemspec and Bundler

If you find that you need to develop against a gem that hasn’t yet been released (for instance, Rails often develops against unreleased Rack, Arel, or Mail gems), you can add individual lines in the Gemfile that tell bundler where to find the gems. It will still use the dependencies listed in the .gemspec for dependency resolution, but it now knows exactly where to find the dependency during gem development.


source "http://www.rubygems.org"

gemspec

# if the .gemspec in this git repo doesn't match the version required by this
# gem's .gemspec, bundler will print an error
gem "rack", :git => "git://github.com/rack/rack.git"

You wouldn’t want to include this information in the .gemspec, which will eventually be released to Rubygems after the in-development gem has also been released. Again, this makes the overall system more resilient, as it doesn’t depend on transient external URLs. This information is purely something used to set up a complete environment during development, which requires some precision.

关于ruby-on-rails - 如何在 gemspec 文件中指定依赖 gem 的路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11427922/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com