由于规范中的日期格式,gemspec 无效

当我在 Gemfile 中包含一个我自己制作的 gem 时,感谢 Bundler (版本1.0.12) ,然后我试着像这样捆绑或耙:

$ rake

我得到了这个错误消息:

Invalid gemspec in [/Users/zagzag/.rvm/gems/ruby-1.9.2-p180@foobar/specifications/myplugin-1.0.0.gemspec]: invalid date format in specification: "2011-04-21 00:00:00.000000000Z"

我正在使用最新的 Mac OS X (10.6.4) ,配置如下:

$ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.4.0]

以及:

$ gem -v
Invalid gemspec in [/Users/zagzag/.rvm/gems/ruby-1.9.2-p180@foobar/specifications/myplugin-1.0.0.gemspec]: invalid date format in specification: "2011-04-21 00:00:00.000000000Z"
1.7.2

我真的不知道如何解决这个问题。谢谢你的建议。

37763 次浏览

Don't specify the time... just the date. 2011-04-21 should work fine.

You may upgraded your gem. To fix this you can edit the gemspecfile directly - from

2011-04-21 00:00:00.000000000Z

to

YYYY-MM-DD

Or upgrade your rails also

sudo gem update rails

It will fix the issue.

Had the same issue. It looks like a bug in rubygems. Here's the commit that fixed it: https://github.com/rubygems/rubygems/commit/21cccd55b823848c5e941093a615b0fdd6cd8bc7

You need to update rubygems and bundler to the latest versions. If you are still having issues after that, then you may need to remove and then reinstall any gems that are giving you problems.

Here is the way I fix the "invalid date format in specification" error:

1.) Go to the specifications folder located at:

/usr/local/lib/ruby/gems/1.8/specifications/

2.) Find the spec that is causing the problem.

3.) Change s.date = %q{2011-05-21 00:00:00.000000000Z} to s.date = %q{2011-05-21}

That's a WIN for me! Good Luck

On my slicehost server the specifications folder was located in a different spot. Here is the path:

/usr/lib/ruby/gems/1.8/specifications

The error provided should give the path to the specifications folder.

This is my environment:

RubyGems Environment:
- RUBYGEMS VERSION: 1.8.10
- RUBY VERSION: 1.9.2 (2011-07-09 patchlevel 290) [x86_64-darwin11.1.0]
- INSTALLATION DIRECTORY: /Users/user/.rvm/gems/ruby-1.9.2-p290@app
- RUBY EXECUTABLE: /Users/user/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
- EXECUTABLE DIRECTORY: /Users/user/.rvm/gems/ruby-1.9.2-p290@app/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-11
- GEM PATHS:
- /Users/user/.rvm/gems/ruby-1.9.2-p290@app
- /Users/user/.rvm/gems/ruby-1.9.2-p290@global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/

I finally managed to find a cause / a way to prevent these errors on my system. I just revert to cucumber and cucumber-rails version 1.0.2. Using the latest versions was doing this...

This is more of a comment to ben hall's answer, but i dont have that privilege yet it seems

gem updates didn't seem to work, im thinking it can't even load the gem because of the bad date format. manually changing the dates was too frustrating to go one by one, so a grep:

grep -i *.gemspec -e '.*s\.date.*=.*%q{\(....-..-..\) \(.*Z\)}

And for sed:

sed -i -e 's/\(.*\)s\.date.*=.*%q{\(....-..-..\) \(.*Z\)}/\1s.date = %q\{\2}/p' ./*.gemspec

And at your own risks!! I'm still a sed newbie, but it worked for me ;)

(Until the bug fix gets into a stable release of Rubygems) I solved it by reinstalling the same version of any warning-generating gems using the --version switch of the gem command.

Please notice the comment from Damian Nowak. These commands do possibly mess up your rubygems!

On Ubuntu 11.10 the following solved this error:

sudo gem install rubygems-update
sudo update_rubygems

The following may work on some systems but not on Debian based:

sudo gem update --system

The shotgun approach: Uninstall all gems and rerun bundler.

  1. gem list --no-version | xargs gem uninstall -aIx
  2. rm -i `rvm gemdir`/specifications/*.gemspec
  3. gem update --system
  4. gem install bundler
  5. bundle install

Here is the command to fix this for all your gems:

perl -p -i -e 's/ 00:00:00.000000000Z//' ~/gems/specifications/*.gemspec

It converts s.date = %q{2011-05-21 00:00:00.000000000Z} to s.date = %q{2011-05-21} and should fix your issue.

Even if you install the latest version of a gem with a valid date format, make sure to gem cleanup GEMNAME afterwards, since gem will still complain about the specifications for the older libraries.

As Ben Hall said, you must fix the gemspec file that may change for system to system. To know what file is see what file is tell in the error report, for example:

Invalid gemspec in [/var/lib/gems/1.8/specifications/svn2git-2.1.2.gemspec]: invalid date format in specification: "2011-12-28 00:00:00.000000000Z"

In this example you must edit "/var/lib/gems/1.8/specifications/svn2git-2.1.2.gemspec" file and change "2011-12-28 00:00:00.000000000Z" for "2011-12-28" in s.date option.

Had this problem still now. Updating Rubygems solved it fine:

gem update --system

Reinstalling your gems can be the solution in many of these slightly different machine states.

In my case:

cd /Library/Ruby/Gems/1.8/specifications &&
sudo rm -rf *

In my case, the other more creative solutions failed.

My issue was getting Invalid gemspec when trying to use cocoapods. I ran gem install cocoapods again and everything was rosy.