Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see the dependency tree just from Gemfile?

Tags:

ruby

bundler

gem

I am getting the following error when doing bundle install

Make sure that `gem install couchbase -v '1.3.3'` succeeds before bundling. 

Now, i have not included this gem in the Gemfile, so it's coming from some dependency. How can i figure out which gem is dependent on this couchbase gem?

Since bundle install is failing and I don't have Gemfile.lock to figure out this dependency.

like image 794
Mohit Verma Avatar asked Sep 27 '13 12:09

Mohit Verma


People also ask

How do I check gem dependencies?

You can always check the reverse dependencies of a gem on rubygems.org. There's a link on the right side panel on the website.

What is the difference between Gemfile and Gemfile lock?

The Gemfile is where you specify which gems you want to use, and lets you specify which versions. The Gemfile. lock file is where Bundler records the exact versions that were installed. This way, when the same library/project is loaded on another machine, running bundle install will look at the Gemfile.

How do I resolve gem dependencies?

Common Attempts To Resolve Ruby Gem Dependencies Bundler can help to resolve dependencies when working with Ruby gems by allowing you to specify a set of gems in a Gemfile, then issue a single command to install them. Bundler then automatically resolves the dependencies for you.


2 Answers

gem dependency (with no args) should show you all gems from current Gemfile with their dependencies.

Edit:

You can also do gem dependency -R (or just dep instead of dependency) if you want to find out which gems use specific (or all) gems.

For deeper dependencies I'd parse output (regex maybe?) of first gem dependencies, pick gem's names and call gem dep on each of them, but that's just a loose idea.

like image 79
zrl3dx Avatar answered Sep 22 '22 17:09

zrl3dx


You can also use bundler to create a dependency graph.

Install graphviz:

gem install ruby-graphviz 

and then:

bundle viz 

Here are an example of a newly created Rails app:

Rails app dependency graph

You can also play with the options:

bundle help viz  
like image 23
Paulo Fidalgo Avatar answered Sep 22 '22 17:09

Paulo Fidalgo