使用自定义gem源的Bundler“无法找到gem ...”错误

时间:2022-06-30 00:21:17

In my Gemfile I require a gem from a custom source with this line:

在我的Gemfile中,我需要使用此行的自定义源中的gem:

gem 'very-secret-gem', source:'https://foo.example.com/'

bundle install completes fine:

捆绑安装完成正常:

$ bundle install
Fetching source index from https://foo.example.com/
Fetching source index from https://foo.example.com/
Fetching gem metadata from https://rubygems.org/........
…
Resolving dependencies...
…
Installing very-secret-gem 1.5.1
…
Bundle complete! 47 Gemfile dependencies, 116 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.

But running commands that use ruby fail (empty Rakefile here):

但运行使用ruby的命令失败(这里为空Rakefile):

$ bundle exec rake -T
Could not find gem 'very-secret-gem (>= 0) ruby' in rubygems repository https://foo.example.com/.
Source does not contain any versions of 'very-secret-gem (>= 0) ruby'
Run `bundle install` to install missing gems.

Running bundle install at this point as advised in the error message will not help.

根据错误消息中的建议,此时运行bundle install将无济于事。

Why is it, and how to fix it?

为什么,以及如何解决它?

If I specify the gem in a source block, it fails just the same:

如果我在源块中指定gem,它就会失败:

source 'https://foo.example.com/' do
  gem 'very-secret-gem'
end

More interestingly, if I specify the sources at the beginning of the file, not tied to any gems, it works fine:

更有趣的是,如果我在文件的开头指定源,而不是绑定任何宝石,它可以正常工作:

source 'https://rubygems.org'
source 'https://foo.example.com/'
gem 'very-secret-gem'

…but bundler advises against it:

...但捆绑者提出反对意见:

Warning: this Gemfile contains multiple primary sources. Using `source`
more than once without a block is a security risk, and may result in
installing unexpected gems. To resolve this warning, use a block to
indicate which gems should come from the secondary source. To upgrade
this warning to an error, run `bundle config disable_multisource true`.

Versions:

$ ruby -v    # => ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]
$ gem -v     # => 2.4.5
$ bundle -v  # => Bundler version 1.8.2

Update

Seems like a bundler bug. The presence of another gem with :path seems to be what triggers it. A test app is here: https://github.com/kch/bundler-source-bug

看起来像捆绑器bug。另一个宝石的存在:路径似乎是触发它的原因。测试应用程序在这里:https://github.com/kch/bundler-source-bug

GH issue for bundler here: https://github.com/bundler/bundler/issues/3417

捆绑商的GH问题在这里:https://github.com/bundler/bundler/issues/3417

2 个解决方案

#1


1  

This should be fixed in Bundler 1.8.3 (released today).

这应该在Bundler 1.8.3(今天发布)中修复。

#2


1  

I would recommend upgrading to atleast bundler 1.8.5 per this issue, which not only has problem with multiple sources but custom paths as well - this way you are not locked into specific gemfile syntax to work around bugs with bundler, custom sources, and bundle exec.

我建议升级到至少捆绑包1.8.5每个问题,这不仅有多个源的问题,但也有自定义路径 - 这样你不会被锁定到特定的gemfile语法来解决与bundle,自定义源和bundle的错误EXEC。

I spent all morning fighting dependency issues and dancing around syntax,

我整个上午都在与依赖问题作斗争并围绕语法跳舞,

gem update bundler

was all I needed, all my problems disappeared.

就是我所需要的,我所有的问题都消失了。

keep an eye on the changelog, there appears to be quite a few minor patches as of late.

密切关注更改日志,最近似乎有很多小补丁。

#1


1  

This should be fixed in Bundler 1.8.3 (released today).

这应该在Bundler 1.8.3(今天发布)中修复。

#2


1  

I would recommend upgrading to atleast bundler 1.8.5 per this issue, which not only has problem with multiple sources but custom paths as well - this way you are not locked into specific gemfile syntax to work around bugs with bundler, custom sources, and bundle exec.

我建议升级到至少捆绑包1.8.5每个问题,这不仅有多个源的问题,但也有自定义路径 - 这样你不会被锁定到特定的gemfile语法来解决与bundle,自定义源和bundle的错误EXEC。

I spent all morning fighting dependency issues and dancing around syntax,

我整个上午都在与依赖问题作斗争并围绕语法跳舞,

gem update bundler

was all I needed, all my problems disappeared.

就是我所需要的,我所有的问题都消失了。

keep an eye on the changelog, there appears to be quite a few minor patches as of late.

密切关注更改日志,最近似乎有很多小补丁。