仅为选定的 gem 捆绑部署

Bundle deployment only for selected gems

我想运行 bundle --deployment 只为系统未提供的一组宝石。我试过使用 --with=group 但它开始为 Gemfile

中的所有宝石做

Bundler 的 --with 选项与您预期的有点不同。让我们先看看 bundle install 手册页 --without--with 选项:

--without=<list>

A space-separated list of groups referencing gems to skip during installation. If a group is given that is in the remembered list of groups given to --with, it is removed from that list. This is a remembered option.

--with=<list>

A space-separated list of groups referencing gems to install. If an optional group is given it is installed. If a group is given that is in the remembered list of groups given to --without, it is removed from that list. This is a remembered option.

重要的是要注意 --with 而不是 只是 --without 的倒数(尽管 --with确实 取消了以前记住的 --without 组,反之亦然),它支持一个完全不同的功能(一个 implemented 最近,大约在 2015 年年中),(向后- compatible) "optional group" 的概念,仅适用于用 optional => true 参数明确标记的组。

重要的是,--with 实现 不会 从默认组或 --without 未指定的任何其他组中排除 gem。

因此,您有两个选项可以将安装限制为仅一组 gem:

  1. 白名单使用 --with 通过将所有组标记为 "optional groups"(使用 :optional => true 参数)并将您希望安装的组传递给 --with,离开排除所有其他可选组。
  2. 使用 --without 的黑名单,将所有您不想安装的群组传递给 --without

不幸的是,这两个选项都无法阻止安装 "default group" 中的 gem(未明确分配给组的 gem),因此您必须将所有可能要排除的 gem 放在某个组中。

以下 Gemfile 示例应该有助于阐明:

gem "rack" # Always installed; impossible to exclude

group :group, :optional => true do
  gem "thin" # Not installed by default; install using --with=group
end
group :another_group, :optional => true do
  gem "wirble" # Not installed by default; install using --with=another_group
end
group :third_group do
  gem "activesupport", "2.3.5" # Installed by default; exclude using --without=third_group
end