Skip to content

Feature proposal: ability to declare all dependencies in Gemfile, not in gemspec #7868

@jeromedalbert

Description

@jeromedalbert

In a non-gem Rails app, all the dependencies are declared in the Gemfile. Nice and tidy.
But in a gem, dependencies nowadays are often declared in 2 different files at the same time: Gemfile for dev dependencies, and my_gem.gemspec for runtime dependencies.

Wouldn't it be nice if all of a gem's dependencies could be declared in the Gemfile? Or is this a crazy idea?

I don't often create new gems but when I do, I wish I could declare all of my dependencies in the Gemfile. Gemfiles are nice. I like them. Declaring dependencies in them feels less clunky than in a gemspec.

Gemfiles can call a gemspec method to add dependencies from the gemspec, among other things.
Conversely, why can't gemspecs call a gemfile (or similar) method to add dependencies from the Gemfile?

It could look something like this:

# my_gem.gemspec

Gem::Specification.new do |spec|
  # ...

  spec.add_gemfile_dependencies
end

or maybe just

Gem::Specification.new do |spec|
  # ...

  spec.gemfile
end

or if you want to include specific Bundler groups:

Gem::Specification.new do |spec|
  # ...

  spec.add_gemfile_dependencies(:default, :release) # or whatever groups you want
end

This would be optional behavior and wouldn't break anything. Here is a hacky but working proof of concept: gist.

Would anyone find this useful, or is it just me?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions