How to specify source in .gemspec file?
Asked Answered
Q

1

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?

Quandary answered 18/7, 2016 at 19:52 Comment(2)
I think this is what you are looking for but not sure how to add this to a gemspec Custom Source for BundlerEmmer
No, I don't need to point to a github repo. I need to use a gem published in rails-assets.org. Thanks anywayQuandary
M
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

Millikan answered 18/7, 2016 at 20:29 Comment(6)
With "bundler file" you mean a Gemfile, right? If so, that's what I'm doing but, It did not work.Quandary
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 firstMillikan
"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.Quandary
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.Millikan
I thought the same thing. That's why I put the gem in the Gemfile.Quandary
@Millikan 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.Emmer

© 2022 - 2024 — McMap. All rights reserved.