Trying to build a gem, getting a Gem::InvalidSpecificationException: "[...] are not files"
Asked Answered
M

2

28

I'm trying to build a custom gem I wrote called client_package but it is failing.

My directory structure looks like this:

client_package
    Gemfile
    Gemfile.lock
    client_package.gemspec
    Rakefile
    Readme.md
    .gitignore
    .git
        ...git files...
    lib
        client_package.rb
        client_package
            version.rb
            api.rb
            ...more...

And my client_package.gemspec looks like this:

# encoding: UTF-8
require File.expand_path('../lib/client_package/version', __FILE__)

Gem::Specification.new do |s|
    s.name = 'client_package'
    s.version = ClientPackage::VERSION
    s.platform = Gem::Platform::RUBY

    s.files = `git ls-files`.split('\n')
    s.executables = `git ls-files -- bin/*`.split('\n').map{ |f| File.basename(f) }
    s.require_paths = ['lib']

    # also have s.authors, s.email, s.homepage, s.summary, s.description

    s.add_dependency 'httparty'
    s.add_dependency 'json'
end

And all my files are committed and the git state is clean.

From within the top client_package directory, I run gem build client_package.gemspec and get this error:

ERROR:  While executing gem ... (Gem::InvalidSpecificationException)
    [".gitignore
Gemfile
Rakefile
Readme.md
client_package.gemspec
lib/client_package.rb
lib/client_package/api.rb
lib/client_package/version.rb
lib/client_package/...more...
"] are not files

This is puzzling to me, because those certainly seem to be files to me. Anyway, I figured there is some path problem if it's not seeing these files, and just doing some trial and error I discovered that if I go up a directory (one above the top-level client_package) and then run gem build client_package/client_package.gemspec it does appear to work at first, creating the file client_package-1.0.0.gem. But something is still wrong. If I then install that gem with gem install client_package-1.0.0.gem that also appears to work. But then this:

require 'rubygems'
require 'client_package'

Returns LoadError: no such file to load -- client_package.

I feel like I must be missing something small but important. Any ideas?

Marriage answered 18/10, 2011 at 23:42 Comment(0)
A
15

This'd be small but important:

Should split('\n') be split("\n")?

Because it looks like

[".gitignore
Gemfile
Rakefile
Readme.md
client_package.gemspec
lib/client_package.rb
lib/client_package/api.rb
lib/client_package/version.rb
lib/client_package/...more...
"]

could be an array containing a single multiline string, not an array of multiple strings.

Adlee answered 19/10, 2011 at 0:23 Comment(1)
Me and my addiction to single-quotes =).Marriage
S
63

Excuses for resurrecting this old thread, but I found another cause: if you did not check in git, some old (deleted files) might interfere: on disk they do not exist, but git ls-files migh report them as being included in the gem.

Check in the files and this exact error is over.

Salomone answered 15/11, 2014 at 11:21 Comment(3)
Cheers @HugoLogmans! I had a deleted file that was causing this problem -- once I ran git rm <deleted_filename> (e.g. staged the file deletion) then I was ok -- I didn't have to actually commit.Hiatt
in this case even if you don't wanna commit, you can just do git add . so that the gem command will ignore the deleted files..Catenane
This saved my day. I removed gem signing certificate but gem build still complaining because git ls-files think the cert is still present.Mending
A
15

This'd be small but important:

Should split('\n') be split("\n")?

Because it looks like

[".gitignore
Gemfile
Rakefile
Readme.md
client_package.gemspec
lib/client_package.rb
lib/client_package/api.rb
lib/client_package/version.rb
lib/client_package/...more...
"]

could be an array containing a single multiline string, not an array of multiple strings.

Adlee answered 19/10, 2011 at 0:23 Comment(1)
Me and my addiction to single-quotes =).Marriage

© 2022 - 2024 — McMap. All rights reserved.