【发布时间】:2020-03-22 10:13:09
【问题描述】:
我在 monorepo 结构中创建了一个名为 registry_client 的 gem。希望我可以在我的frontend-app 内部使用它。但是,当我尝试使用 bundler bundle exec ruby app.rb 运行它时遇到了这个错误:
LoadError: cannot load such file -- registry_client
frontend-app 中的 Gemfile:
source 'https://rubygems.org'
gem 'registry_client', git: 'https://github.com/.../some_repo.git', branch: 'master', glob: 'registry-client/*.gemspec'
我在bundle install 和bundle list 之后验证了gem 安装成功:
Gems included by the bundle:
...
* registry_client (0.1.1 f93f5bd)
...
这是回购结构:
├── frontend-app
│ ├── Gemfile
│ ├── Gemfile.lock
│ ├── Rakefile
│ ├── app.rb
│ ├── config
│ ├── config.ru
│ ├── test
│ └── views
└── registry-client
├── Gemfile
├── lib
├── registry_client.gemspec
└── test
app.rb
require 'registry_client'
...
registry_client.gemspec
# frozen_string_literal: true
require_relative 'lib/version'
Gem::Specification.new do |spec|
spec.name = 'registry_client'
spec.summary = 'Registry client for using Redis as Service Registry.'
spec.authors = ['Author']
spec.version = RegistryClient::VERSION
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(File.expand_path(__dir__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']
end
编辑:添加 gemspec 文件
【问题讨论】:
-
运行
gem environment,获取INSTALLATION DIRECTORY的值。然后将/gems添加到安装目录并使用ls命令列出其内容。你在那儿看到你的宝石了吗? -
@PetrGazarov 目录中缺少 gem,但我相信可能是预期的行为,来自捆绑程序文档:
Note that because RubyGems lacks the ability to handle gems from git, any gems installed from a git repository will not show up in gem list. They will, however, be available after running Bundler.setup. -
@PetrGazarov 这是
bundle info registry_client下显示的内容:* registry_client (0.1.1 f93f5bd) Summary: Registry client for using Redis as Service Registry. Path: /Users/julianho/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/bundler/gems/service-api-example-impl-f93f5bd49c46/registry-client -
当你
ls /Users/julianho/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/bundler/gems/service-api-example-impl-f93f5bd49c46/registry-client时,你看到registry_client.gemspec了吗? -
是的。
total 24 drwxr-xr-x 7 julianho staff 224B Mar 22 16:13 . drwxr-xr-x 10 julianho staff 320B Mar 22 16:13 .. -rw-r--r-- 1 julianho staff 115B Mar 22 16:13 Gemfile -rw-r--r-- 1 julianho staff 270B Mar 22 16:13 Gemfile.lock drwxr-xr-x 6 julianho staff 192B Mar 22 16:13 lib -rw-r--r-- 1 julianho staff 832B Mar 22 16:13 registry_client.gemspec drwxr-xr-x 3 julianho staff 96B Mar 22 16:13 test