Gem Gemfile 里同一个 Gem 可以根据不同的 Ruby 版本制定不同的版本吗?

inetufo · 2012年06月20日 · 最后由 hooopo 回复于 2012年06月21日 · 5924 次阅读

比如 xxx 的 gem 需要在 1.8, 1.9 用不同的版本 platform :mingw_18 do gem 'xxx', "~> 2.7" end

platform :mingw_19 do gem 'xxx' end

但是这样写好象不行,bundle 报错

报什么错啊?

PLATFORMS (:platforms)
If a gem should only be used in a particular platform or set of platforms, you can specify them. Platforms are essentially identical to groups, except that you do not need to use the --without install-time flag to exclude groups of gems for other platforms.

There are a number of Gemfile platforms:

ruby
C Ruby (MRI) or Rubinius, but NOT Windows
ruby_18
ruby AND version 1.8
ruby_19
ruby AND version 1.9
mri
Same as ruby, but not Rubinius
mri_18
mri AND version 1.8
mri_19
mri AND version 1.9
rbx
Same as ruby, but only Rubinius (not MRI)
jruby
JRuby
mswin
Windows
mingw
Windows 'mingw32' platform (aka RubyInstaller)
mingw_18
mingw AND version 1.8
mingw_19
mingw AND version 1.9
As with groups, you can specify one or more platforms:

gem "weakling",   :platforms => :jruby
gem "ruby-debug", :platforms => :mri_18
gem "nokogiri",   :platforms => [:mri_18, :jruby]
All operations involving groups (bundle install, Bundler.setup, Bundler.require) behave exactly the same as if any groups not matching the current platform were explicitly excluded.

You cannot specify the same gem twice with different version requirements. You s pecified: XXX(= 2.7) and XXX(~> 3.0)

试试 gem 'xxxxx', :require => false if RUBY_VERSION =~ xxxxxxxx

#2 楼 @inetufo 这个错误很明显呀 可能其他 gem 依赖了 xxx,和你指定的 xxx 版本号不匹配

需要 登录 后方可回复, 如果你还没有账号请 注册新账号