When downgrading a gem, can bundler automatically downgrade the gem's dependencies along with it?

StackOverflow https://stackoverflow.com/questions/11942985

سؤال

Earlier I changed a gem version in the Gemfile for my Rails project. I ran bundler update gemname, and this installed more up-to-date versions of several dependencies, which kind of surprised me.

Now, I need to downgrade to the old version of the gem. I've changed the version back in my Gemfile, and run bundler upgrade gemname again (and bundler install for good measure), but now the gems that were upgraded earlier (the dependencies) are still the newer versions (I'd guess the gem didn't specify versions, so it's just using whatever is latest?).

Is there a way to downgrade those dependencies back to where they were before upgrading the gem?

هل كانت مفيدة؟

المحلول

Bundler can't know the maximum version of a dependent gem if the depending gem doesn't specify it. Unless downgrading the gem actually changes its dependencies, your only real option is to checkout a previous version of your gemfile.lock from version control. Otherwise no, you cannot do what you're trying to do; Bundler will respect your current gemfile.lock which will not change unless the dependencies of your gem change upon downgrading it.

نصائح أخرى

You could always specify the dependent gems, with your required version numbers, in your Gemfile. This will force bundler to re-evaluate the dependencies and downgrade them as required. It's not ideal but you would be able to remove the specified gems in the future once the versions sorted themselves out.

I would have added this as a comment but I can not due to my reputation, so I hope someone finds this useful.

I also did what nmott suggested. Just add the dependency in your Gemfile, e.g.: gem 'gem-name', '~> 1.5.0'

and run bundle update gem-name

Then when your dependency gets downgraded, remove the line from the Gemfile and keep it as it was originally.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top