0

我有一个我们将调用的 gem, mygem它有一个用作 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会抑制部分错误消息,但仍无法执行,除非bundle install其他应用程序的 Gemfile 上运行:

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

如何解决这个问题?

4

1 回答 1

0

该错误看起来很典型。它是说它在你的 gemfile 中找不到 gem,它会加载你的依赖项。通常 bundle install 会在没有问题的情况下将它们全部添加,但我之前遇到过这样的问题,不得不手动将条目放入 gemfile 中。

如果您正在制作示例,请尝试添加到 gemfile:

gem 'differ'
于 2016-08-31T22:04:27.773 回答