Ruby 如何避免在Gemfile和.gempec中指定gem依赖项?

Ruby 如何避免在Gemfile和.gempec中指定gem依赖项?,ruby,gem,Ruby,Gem,我正在创建一个Gem,它需要在用户的系统上安装其他Gem。我在做传统的事情,并在Gemfile中指定我的依赖项,以便bundle安装识别 Gem规范文件似乎也可以通过以下方式找到特定的依赖项: Gem::Specification do |s| s.add_runtime_dependency... s.add_development_dependency... end 如何避免在这两个位置指定依赖项?在您的GEM文件中: #!/usr/bin/env ruby gemspec Ge

我正在创建一个Gem,它需要在用户的系统上安装其他Gem。我在做传统的事情,并在
Gemfile
中指定我的依赖项,以便
bundle安装
识别

Gem规范文件似乎也可以通过以下方式找到特定的依赖项:

Gem::Specification do |s|
  s.add_runtime_dependency...
  s.add_development_dependency...
end

如何避免在这两个位置指定依赖项?

在您的GEM文件中:

#!/usr/bin/env ruby
gemspec
Gem::Specification do |s|
  s.add_runtime_dependency('some-gem-for-production', '>= 3.0.0')
  s.add_development_dependency('some-gem-for-development', '>= 2.0.0')
end
在您的.gemspec中:

#!/usr/bin/env ruby
gemspec
Gem::Specification do |s|
  s.add_runtime_dependency('some-gem-for-production', '>= 3.0.0')
  s.add_development_dependency('some-gem-for-development', '>= 2.0.0')
end

现在,当您运行
bundle install
时,Gemfile告诉
bundle
查看Gem规范文件中的依赖项。

您是否尝试将代码
Gem::Specification do | s |
等放入Gemfile中?无论如何,我看到的项目使用了这两种方法,但gempec用于设置运行时,有时用于开发依赖项,Gemfile用于路径内developent、test和其他分组依赖项。