Daniel Viglione
Daniel Viglione

Reputation: 9477

Custom gem dependencies not added to Gemfile.lock?

I wrote a gem. In my Gem's gemspec file, I have something like this:

 spec.add_development_dependency "aws-sdk-mturk", '~> 1.3'

And in one of my Gem's files I have:

require 'aws-sdk-mturk'

This gem is not published to rubygems.org. It is a private gem on my private git account. So I wanted to add it to my Rails project and so I did this in Gemfile:

gem "my_gem", git: "https://git.mygitlab.net/myuser/mygem.git", branch: "master"

And I notice when I run bundle install and then subsequently bundle update --source mygem, in Gemfile.lock it does not show any of the dependencies, including aws-sdk-mturk.

So when I try to run Rails application, I get this error:

gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:274:in `require': cannot load such file -- aws-sdk-mturk (LoadError)

When doesn't bundler/the Rails application read the .gemspec dependencies of my private gem?

Upvotes: 2

Views: 1020

Answers (2)

Lars Haugseth
Lars Haugseth

Reputation: 14881

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.

Upvotes: 0

Luiz E.
Luiz E.

Reputation: 7279

Change to add_runtime_dependency instead add_development_dependency.

From the docs

Development dependencies aren't installed by default and aren't activated when a gem is required.

Upvotes: 0

Related Questions