Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "add_dependency vs add_runtime_dependency" rule #943

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5626,9 +5626,9 @@ The gemspec should not contain `RUBY_VERSION` as a condition to switch dependenc
# bad
Gem::Specification.new do |s|
if RUBY_VERSION >= '2.5'
s.add_runtime_dependency 'gem_a'
s.add_dependency 'gem_a'
else
s.add_runtime_dependency 'gem_b'
s.add_dependency 'gem_b'
end
end
----
Expand All @@ -5639,6 +5639,26 @@ Fix by either:
* Add both gems as dependency (if permissible).
* If development dependencies, move to Gemfile.

=== `add_dependency` vs `add_runtime_dependency` [[add_dependency_vs_add_runtime_dependency]]

Prefer `add_dependency` over `add_runtime_dependency` because `add_dependency` is considered soft-deprecated
and the Bundler team recommends `add_dependency`.

[source,ruby]
----
# bad
Gem::Specification.new do |s|
s.add_runtime_dependency 'gem_a'
end

# good
Gem::Specification.new do |s|
s.add_dependency 'gem_a'
end
----

See https://github.com/rubygems/rubygems/issues/7799#issuecomment-2192720316 for details.

== Misc

=== No Flip-flops [[no-flip-flops]]
Expand Down