捆绑器和仅限捆绑器 - 禁止重复 gem 警告
Bundler and bundler-only - suppress duplicate gem warning
我在我的 gem 文件上使用捆绑器来执行应用程序,发现使用 bundler-only
可以方便地只选择 gem 的一个子集仅部署需要。
所以在我的部署机器上,我使用 bundle-only
,它只会安装 gems 在 deploy
组下的命名空间。
但是,因此我需要复制一些 gem(例如,我的部署需要向 slack 发送通知,因此我的全局命名空间和我的 :deploy-only 命名空间。
这会导致多次警告
Your Gemfile lists the gem slack-notifier (>= 0) more than once. You
should probably keep only one of them. While it's not a problem now,
it could cause errors if you change the version of one of them later
有没有办法抑制警告? (如果可能的话,只有那些 gems)
不要多次列出宝石。这个警告是有充分理由的。
您可以在 Gemfile
中同时将多个命名空间下的 gem 分组,如下所示:
group :deploy, :somethingelse do
gem 'slack-notifier'
end
group :deploy do
# Deploy-ONLY gems
end
group :somethingelse
# Somethingelse-ONLY gems
end
或者,如果您愿意,可以内联进行分组:
gem 'slack-notifier', group: [:deploy, :somethingelse]
有关详细信息,请阅读关于 Gemfile 组的 bundler documentation。
一种替代方法是维护所有 groups
的列表,并系统地包括 , groups: groups
# Gemfile
groups = [:deploy, :x, :y, :z, ...] # Maintain this list as you add groups
# Gems needed except in deploy
gem :a
gem :b
...
# Gems that are also required for deploy
gem :d1, groups: groups
gem :d2, groups: groups
# Gems that are required ONLY in deploy
group :deploy do
gem :dep_only1
gem :dep_only2
end
所以下面的工作没有警告
bundle --without deploy # Will ignore deploy group
bundle-only deploy # Will install only deploy gems including those that are also needed by the app
我在我的 gem 文件上使用捆绑器来执行应用程序,发现使用 bundler-only
可以方便地只选择 gem 的一个子集仅部署需要。
所以在我的部署机器上,我使用 bundle-only
,它只会安装 gems 在 deploy
组下的命名空间。
但是,因此我需要复制一些 gem(例如,我的部署需要向 slack 发送通知,因此我的全局命名空间和我的 :deploy-only 命名空间。 这会导致多次警告
Your Gemfile lists the gem slack-notifier (>= 0) more than once. You should probably keep only one of them. While it's not a problem now, it could cause errors if you change the version of one of them later
有没有办法抑制警告? (如果可能的话,只有那些 gems)
不要多次列出宝石。这个警告是有充分理由的。
您可以在 Gemfile
中同时将多个命名空间下的 gem 分组,如下所示:
group :deploy, :somethingelse do
gem 'slack-notifier'
end
group :deploy do
# Deploy-ONLY gems
end
group :somethingelse
# Somethingelse-ONLY gems
end
或者,如果您愿意,可以内联进行分组:
gem 'slack-notifier', group: [:deploy, :somethingelse]
有关详细信息,请阅读关于 Gemfile 组的 bundler documentation。
一种替代方法是维护所有 groups
的列表,并系统地包括 , groups: groups
# Gemfile
groups = [:deploy, :x, :y, :z, ...] # Maintain this list as you add groups
# Gems needed except in deploy
gem :a
gem :b
...
# Gems that are also required for deploy
gem :d1, groups: groups
gem :d2, groups: groups
# Gems that are required ONLY in deploy
group :deploy do
gem :dep_only1
gem :dep_only2
end
所以下面的工作没有警告
bundle --without deploy # Will ignore deploy group
bundle-only deploy # Will install only deploy gems including those that are also needed by the app