Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working with bundler and different platform gem requirements

Tags:

ruby

bundler

I seem to struggling with what I thought was standard functionality of bundler, according the manual The ability to specifiy that gems should be required on for certain platforms using the :platforms option or platforms block

I want to specifcy a different version of a gem dependent on the version of ruby used

source "http://rubygems.org"
gem "trollop", "~> 1.16.2"
gem "chronic", "~> 0.6.4"
gem "highline", "~> 1.6.2"
gem "colorize", "~> 0.5.8"
gem "queryparams", "~> 0.0.3"

platforms :ruby_18 do
  gem "json"
  gem "activesupport", "~>2.8.9"
end

platforms :ruby_19 do
  gem "activesupport", "~>3.1.3"
end

However this fails when running bundle install

You cannot specify the same gem twice with different version requirements.
You specified: activesupport (~> 2.8.9) and activesupport (~> 3.1.3)
like image 843
Rob Avatar asked Dec 02 '11 17:12

Rob


People also ask

What is the difference between gem install and bundle install?

Almost seems like running 'gem install' adds it to the global available gems (and hence terminal can run the package's commands), whereas adding it to the gemfile and running bundle install only adds it to the application. Similar to npm install --global. that's basically it.

What is bundler in gem?

Bundler provides a consistent environment for Ruby projects by tracking and installing the exact gems and versions that are needed. Bundler is an exit from dependency hell, and ensures that the gems you need are present in development, staging, and production. Starting work on a project is as simple as bundle install .

What are platforms in Gemfile?

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), Rubinius, or TruffleRuby, but not Windows.

Where does bundler install gems?

Show activity on this post. I know that when using gem install , the gem will be stored under /home/username/. rvm/gems/, under which gemset the gem was installed.


1 Answers

You don't need 2 different Gemfiles in order to achieve platform-specific gem-requirements. Just check for the RUBY_VERSION and put your gems in some sort of conditional clause:

if(defined?(JRUBY_VERSION))
  gem 'warbler'
else
  case(RUBY_VERSION)
  when('1.8.7')
    gem 'ruby-debug'
  when('1.9.2')
    gem 'ruby-debug19'
  when('1.9.3')
    gem 'debugger'
  end
end

That should do the trick.

With best regards,

like image 54
klaffenboeck Avatar answered Sep 27 '22 21:09

klaffenboeck