Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Version specific gem :platform in Gemfile doesn't do anything that I can see #4420

Closed
kjg opened this issue Mar 31, 2016 · 8 comments
Closed

Comments

@kjg
Copy link

kjg commented Mar 31, 2016

Running Bundler Version 1.11.2

If I have a Gemfile that specifies

platforms :ruby_18 do
  gem "rake", "< 11.0"
end
platforms :ruby_20 do
  gem "rake", "> 11.0"
end

I get the error

[!] There was an error parsing `Gemfile`: You cannot specify the same gem twice with different version requirements.
You specified: rake (< 11.0) and rake (> 11.0). Bundler cannot continue.

Am I just missing the point of the version specific platform option on the gems?

Is there anyway to meet this use case of installing a different version of the gem depending on the version of ruby?

Even though rake specifies it's REQUIRED RUBY VERSION in it's gemfile, bundler still tries to install >11 when I'm on ruby 1.8.7 for example, so using platforms :ruby_20 is what I'd expect to have to do to work around this, but that doesn't seem to work either.

@segiddins
Copy link
Member

There's no way to do this -- you'll need to stick with 10.x for 1.8 compatibility.

@kjg
Copy link
Author

kjg commented Mar 31, 2016

What is the intended use case for the version specific platform identifiers? The docs indicate that it does constrain the ruby version http://bundler.io/v1.11/man/gemfile.5.html#PLATFORMS-platforms-

@segiddins
Copy link
Member

Yes, they do, but a single bundle must be self-coherent, regardless of different groups, platform blocks, install_if blocks, etc

@coilysiren coilysiren added this to the 1.14 — Better Platform Support milestone Sep 21, 2016
@coilysiren coilysiren removed this from the 1.14 — Better Platform Support milestone Sep 21, 2016
@coilysiren
Copy link
Contributor

So as far as I can tell, this is best interpreted as a feature request to allow Bundler to have different versions of the same gem on different platforms? cc @kjg

@segiddins
Copy link
Member

If that's the feature request, we can close this -- that's simply not in the cards. It goes completely against bundler's promise of installing the same dependencies everywhere. If this functionality is something the user wants, they will have to use a regular ruby conditional and deal with the fact that their lockfile with change every time that they switch ruby versions

@kjg
Copy link
Author

kjg commented Sep 21, 2016

Gems inside the platforms :ruby_18 block still seem to get installed even on ruby 2.0

@antoineco
Copy link

antoineco commented Sep 21, 2016

@kjg I confirm that. The following blocks are enforced with all Ruby versions:

platforms :ruby_18 do
  # https://github.com/rspec/rspec-core/issues/1864
  gem 'rspec', '< 3.2.0',  :require => false
  gem 'rake',  '< 11.0.0', :require => false
end

platforms :ruby_18, :ruby_19 do
  gem 'json',      '< 2.0.0', :require => false
  gem 'json_pure', '< 2.0.0', :require => false
end

@segiddins
Copy link
Member

Closing, this is how the :platform filter is intended to work -- it only changes which gems are activated at runtime and intentionally does not allow specifying different versions of the same gem.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants