How to Force a Gem's Dependencies in Gemfile

Can I force a gem's dependencies in gemfile?

You'll need to explicitly specify the B gem in your Gemfile to use a git repository or another version. As long as A 1.0.0 is compatible with B 1.0.1 you'll be fine. If it is only compatible with B 1.0.0 then you'll have to create your own fork of the A gem and upgrade the gemspec to be compatible with B 1.0.1 and then use that repository as your gem for A instead of the rubygems version.

Here is a sample Gemfile that should give you what you want, provided A 1.0.0 is compatible with B 1.0.1.

gem 'B', :git => 'git://github.com/B/B.git', :tag => '1.0.1'
gem 'A', '~> 1.0.0'

How to force a version in Bundle Gemfile?

Someone has submitted a pull request to support listen v1 and v2 in fontcustom: https://github.com/FontCustom/fontcustom/pull/191 Unfortunately, it has not been accepted yet.

You can use the forked version by changing your Gemfile to:

source 'https://rubygems.org'
gem 'jekyll', '~> 2.4.0'
gem 'fontcustom', git: 'https://github.com/twalpole/fontcustom.git', branch: 'listen'

Then, run bundle install.

Custom gem dependencies not added to Gemfile.lock?

Change add_development_dependency to add_runtime_dependency if your code needs this other gem during runtime.

Quote from https://guides.rubygems.org/patterns/#declaring-dependencies

Runtime vs. development

RubyGems provides two main “types” of dependencies: runtime and development. Runtime dependencies are what your gem needs to work
(such as rails needing activesupport).

Development dependencies are useful for when someone wants to make modifications to your gem. When you specify development dependencies,
another developer can run gem install --dev your_gem and RubyGems will
grab both sets of dependencies (runtime and development). Typical
development dependencies include test frameworks and build systems.

How do I force Bundler to reinstall all of my gems?

bundle install --redownload

See the reference for bundle install: https://bundler.io/v2.2/man/bundle-install.1.html

or

bundle install --force

For older versions of bundler

Gemfile gem installation and gemspec dependencies

As stated in the gem specification, the list of gems that you provide through add_dependency will be use to make sure those are already installed in the system during the installation process (i.e gem install). So this line:

my-gem/my-gem.gemspec reads spec.add_dependency "my-gem-2"

Will trigger the verification of whether or not the gem is installed in the system, but it will not trigger any automatic installation of such gem, as Bundler would do.

This other line (inside of your gem):

gem "my-gem-2", :git => "git@github.com:MyCompany/my-gem-2.git"

Specify that a gem should come from a git repository with a .gemspec at its root.

For more details: Gems from git repositories



Related Topics



Leave a reply



Submit