11

I'm building a gem that uses rails-assets-growl gem. This gem can be added to my Gemfile using a different source than 'https://rubygems.org' like this:

source 'https://rails-assets.org' do
  gem 'rails-assets-growl'
end

This works fine in development mode. But, when I publish my gem in rubygems.org growl gem is not included as dependency.

gem dependencies

I think, this is beacuse I need to specify the https://rails-assets.org source in gemspec instead of Gemfile. But, I'm not sure.

So, the question is:

How can I specify a source for a gem in gemspec file?

Leantraxxx
  • 4,506
  • 3
  • 38
  • 56
  • I think this is what you are looking for but not sure how to add this to a gemspec [`Custom Source for Bundler`](http://bundler.io/git.html#custom-git-sources) – engineersmnky Jul 18 '16 at 20:09
  • No, I don't need to point to a github repo. I need to use a gem published in https://rails-assets.org. Thanks anyway – Leantraxxx Jul 18 '16 at 21:08

1 Answers1

4

In order to publish a gem and list the dependencies, you need to use a gem specification, which is different from a Gemfile

In order to list rails-assets-growl as a dependency, you will need to add it to your gem specification. The problem here is that you cannot add a gem with a external location to rubygems, so you will need to first publish rails-assets-growl into rubygems.

If that doesn't work for you, you can still go and create your gem, add a bundler file where you will add the rails-assets-growl and then you will add the gemspec to it, like:

source 'https://rubygems.org'

gemspec

source 'https://rails-assets.org' do
  gem 'rails-assets-growl'
end

the gem won't be listed as a dependency in the last case, but it will be on the gemfile to be used by other people

rorra
  • 9,593
  • 3
  • 39
  • 61
  • 1
    With "bundler file" you mean a Gemfile, right? If so, that's what I'm doing but, It did not work. – Leantraxxx Jul 18 '16 at 21:05
  • It won't work, because a Gemfile only list dependencies specified in the gemfile specification. If you want to list **rails-assets-growl** as a dependency, you don't have other option than publishing **rails-assets-growl** into rubygems first – rorra Jul 18 '16 at 21:08
  • "If that doesn't work for you, you can still go and create your gem, add a bundler file where you will add the rails-assets-growl and then you will add the gemspec to it" what are you saying here? If I understand, you are saying: 1 - I can put growl in Gemfile. 2 - I won't see the dependency listed in rubygems (thats ok) 3 - That will work when I'll use my gem in a project. I'm saying that 3 does not work. – Leantraxxx Jul 18 '16 at 21:18
  • 1
    that's weird, at some projects I was involved, we break the systems in small private gems, and published them on our own servers by not including them on the gemspec but on the Gemfile. The gemfile with gemspec just tell bundler to load the gems on the gemspec. Whenever we included these gems, it worked fine because Bundler automatically gets the dependencies and load all of them. – rorra Jul 18 '16 at 21:32
  • I thought the same thing. That's why I put the gem in the Gemfile. – Leantraxxx Jul 18 '16 at 21:36
  • @rorra you may have multiple sources in your Gemfile which allows this to work but the gem spec can't do that best way might be to include a rakefile and then tell users to call the rake task and it can add the additional source. – engineersmnky Jul 20 '16 at 00:39