如何使用gemspec add_runtime_dependency和"bundle install"



我有一个代码库,它有一个gemspec文件,比如:

require "rubygems"
::Gem::Specification.new do |specification|
specification.add_development_dependency "yard", "~> 0.9"
specification.add_runtime_dependency "dry-validation", "~> 0.13"
end

bundle install将安装这两种依赖类型。所以我只想为我的CI脚本安装运行时依赖项。我看到bundle install --with <group>存在,但我没有组。以交互方式运行,返回的规范具有从.groups返回的空结果。我很乐意将这两个世界合理化。我必须为每个gem依赖项显式添加一个组吗?add_runtime_dependence和add_development_dependence会有区别吗?

来自bundler的文档

因为我们在Gemfile中有gemspec方法调用,Bundler会自动将这个gem添加到一个名为"development"的组中,然后我们可以在任何时候用以下行引用这些gem:

Bundler.require(:default, :development)

在您的情况下,如果您希望安装所有不用于开发的rubygems,请尝试

bundle install --without development

对于未来的bundler版本,您可以在本地(或全局(配置

bundle config set --local without 'development'

要使其全部工作,请验证您的项目中是否有Gemfile,它看起来像

# frozen_string_literal: true
source 'https://rubygems.org'
gemspec

最新更新