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

Bundler.require not loading .gemspec dependencies #2018

Closed
jch opened this issue Jul 7, 2012 · 10 comments
Closed

Bundler.require not loading .gemspec dependencies #2018

jch opened this issue Jul 7, 2012 · 10 comments

Comments

@jch
Copy link

jch commented Jul 7, 2012

I'm not sure if this is intentional behavior, but from this documentation, I expected that Bundler.require :default would also require the runtime dependencies specified in .gemspec. I've created a demo gem showing this.

# gemspec
Gem::Specification.new do |gem|
  # snip
  gem.add_dependency 'rack'
end
# Gemfile
source 'https://rubygems.org'

# Specify your gem's dependencies in bundler-issue.gemspec
gemspec
# test.rb
require 'bundler'
Bundler.require :default  # <-- I expected this to load dependencies in from the gemspec

puts "Dependency loaded: " + defined?(Rack).inspect

If I explicitly require rack, it works as expected, and Gemfile.lock lists rack as expected.

@indirect
Copy link
Member

indirect commented Jul 7, 2012

Gems must load their own dependencies. If they don't, they are no longer functional Rubygems.

On Jul 6, 2012, at 5:05 PM, Jerry Cheungreply@reply.github.com wrote:

I'm not sure if this is intentional behavior, but from this documentation, I expected that Bundler.require :default would also require the runtime dependencies specified in .gemspec. I've created a demo gem showing this.

# gemspec
Gem::Specification.new do |gem|
 # snip
 gem.add_dependency 'rack'
end
# Gemfile
source 'https://rubygems.org'

# Specify your gem's dependencies in bundler-issue.gemspec
gemspec
# test.rb
require 'bundler'
Bundler.require :default  # <-- I expected this to load dependencies in from the gemspec

puts "Dependency loaded: " + defined?(Rack).inspect

If I explicitly require rack, it works as expected, and Gemfile.lock lists rack as expected.


Reply to this email directly or view it on GitHub:
#2018

@ghost
Copy link

ghost commented Jul 7, 2012

Additional note: Bundler.require will only require those gems that are listed in the Gemfile. Dependencies (rack in this case`) must be loaded manually, as @indirect already said.

@jch
Copy link
Author

jch commented Jul 7, 2012

Thanks for the clarification!

@jch jch closed this as completed Jul 7, 2012
@ianfixes
Copy link

Gems must load their own dependencies.

Can you explain what this means, to someone who is unfamiliar with this process?

@indirect
Copy link
Member

@ifreecarve no problem. Gems are not able to use Bundler, so they should simply require the libraries they need.

@ianfixes
Copy link

By this you mean that in whatever ruby source files are contained in the gem, you say require 'some_library'? And bundler uses this to determine/download dependencies when you bundle install?

(I was able to solve the problem I was having, but I have no idea how.)

@indirect
Copy link
Member

Not exactly. When you create a gem, list any other gems you depend on in your gemspec. Then, inside the code of your gem, require those gems. So, if your gem depends on Rack, you would add a line like s.add_runtime_dependency "rack", "~> 1.2" to your gemspec, and then a line like require "rack" to your gem code.

Bundler will use the gemspec to know what to install and add to the load path; your gem will then require it and be able to use it.

On Wed, May 20, 2015 at 12:06 PM, Ian notifications@github.com wrote:

By this you mean that in whatever ruby source files are contained in the gem, you say require 'some_library'? And bundler uses this to determine/download dependencies when you bundle install?

(I was able to solve the problem I was having, but I have no idea how.)

Reply to this email directly or view it on GitHub:
#2018 (comment)

@ianfixes
Copy link

Hmm... that's what I was doing. Bundler seemed to be ignoring what i put in s.add_runtime_dependency, which is why I asked. I had tried a variety of things, and although it works now I'm not sure what fixed it.

codeforkjeff pushed a commit to upenn-libraries/blacklight_alma that referenced this issue Jan 12, 2017
@maschwenk
Copy link

@indirect would this potentially change now that bundler is part of Ruby std lib?

@colby-swandale
Copy link
Member

No, this behavior is not changing.

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

No branches or pull requests

5 participants