在Gem :: Specification.reset中安装了宝石的Ruby未解析的规范

时间:2016-08-31 21:00:44

标签: ruby rubygems bundler gemspecs

我有一个我们称之为mygem的gem,它有一个可执行文件用作CLI工具。

文件mygem/bin/mygem

#!/usr/bin/env ruby
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'bundler/setup'
....code goes here....

mygem.gemspec

Gem::Specification.new do |gem|
  gem.bindir      = 'bin'
  gem.executables = ['mygem']
end

构建并安装:

gem build mygem.gemspec
gem install mygem-0.1.0.gem
<optionally bundle install, but that won't fix the error>

最后,我可以从命令行成功调用mygem并运行脚本。

问题是它只能从包含Gemfile的文件夹中运行。否则,系统会输出错误:

WARN: Unresolved specs during Gem::Specification.reset:
      json (>= 0)
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
Could not find differ-0.1.2 in any of the sources
Run `bundle install` to install missing gems.

此错误消息中显示的实际gem会因当前目录中的Gemfile而异。

运行bundle exec mygem会抑制部分错误消息,但除非在其他应用程序的Gemfile上运行bundle install,否则仍无法执行:

Could not find differ-0.1.2 in any of the sources
Run `bundle install` to install missing gems.

如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

错误看起来非常典型。它说它无法在你的gemfile中找到gem,它会加载你的依赖项。通常bundle install会将它们添加到所有没有问题的地方,但我之前遇到过这样的问题,并且必须手动将条目放入gemfile中。

如果你是一个例子,请尝试添加到gemfile:

gem 'differ'