Saturday, January 12, 2008

RubyGems: Gem::Specification#autorequire= Deprecated; Use Require Instead

Packaging up gemspecs which up until now had been trouble-free produced two warnings for me:

WARNING: no rubyforge_project specified
WARNING: deprecated autorequire specified

The no rubyforge_project one doesn't check to see if you've already declared a rubyforge value for homepage:

s.homepage = ""
s.rubyforge_project = "rubotz"

But if you don't do both, you get either a no homepage specified or a no rubyforge project specified warning.

The deprecated autorequire warning is a little weirder. It's pretty obvious that you can just use require instead; what's less obvious is why you have autorequire instead. My gemspec was initially generated by Hoe, so like with any generated code, there's a certain air of mystery involved. You have to wonder if require is enough, because if it was enough, why did autorequire exist in the first place?

Fortunately, Google can find you an excellent explanation from Jim Weirich:

The autorequire feature is a holdover from the days when regular requires didn't work in rubygems. It avoided the need to do a require_gem *and* a regular require. Since the regular require is all that is needed today, autorequire is a holdover from the past.

Long story short, just use require.