Adding a customized version of bundler as a dependency in a Gemfile - ruby

How can I make a typical gem setup (as generated by bundle gem) run a customize version of bundler?
I've added:
#group :development do
gem "bundler", github: 'pjump/bundler'
#end
to my Gemfile (with or without the the hash symbols), and bundle install works, but bundle exec keeps telling me that the bundler repo is not yet checked out. The only way I can make it work for now is by installing the customized version with gem istall and not specifying a bundler dependency in the package at all.

Bundler isn't able to bootstrap itself from a Gemfile, so adding a customized version to your Gemfile will not do what you want. Installing it with gem install is the correct solution (or running rake install from the forked Bundler repo directory, which builds and installs the gem in one step).

Related

Can bundler use locally installed gems when a custom source is specified

I have a project where we are building a custom gem which is hosted on a private gemserver (gemfury). This gem is a dependency in multiple Gemfiles where I need to run tests.
So I have a Gemfile that looks like this:
source "https://rubygems.org"
source 'https://gem.fury.io/custom/' do
gem 'my-custom-gem', '0.0.42'
end
gem 'aws-sdk-iotdataplane', '~>1.15.0'
gem 'bson', '~>4.4.2'
gem 'mongoid', '~>6.1.1'
.
.
.
I build and install the gem locally with rake install (which works fine) and then attempt to run bundle install on the above Gemfile.
I get the following error:
$ bundle install
Fetching gem metadata from https://gem.fury.io/custom/..
Could not find gem 'my-custom-gem (= 0.0.42)' in rubygems repository https://gem.fury.io/custom/ or installed locally.
The source contains the following versions of 'my-custom-gem': 0.0.1, 0.0.4
It is my understanding that if the gem is installed locally on the system, bundler should not attempt to fetch it from the source.
Is this correct?
If I remove the custom source block from around the gem line, it will use the local gem and the fact that the error message says "... or installed locally" really seems to suggest this should work.

gem cleanup removes needed versions

When I run gem cleanup -d it lists several gem versions that are dependencies. The gems that depend on them are listed in the Gemfile in a jekyll install I have via my github repo, which I suspect is why gem doesn't see the dependencies.
Is there a way to tell gem to look at the jekyll install's Gemfile for dependencies?
Or is it actually another problem?
TIA.

Unable to require gem from git with RVM

I cannot require a custom gem I developed to a ruby project. I use RVM. Here's what I've done:
I added gem locally via Gemfile:
gem 'my-gem', git: 'https://github.com/username/my-gem.git'
I installed the gem:
bundle
Fetching https://github.com/username/my-gem.git
Fetching gem metadata from https://rubygems.org/............
Fetching version metadata from https://rubygems.org/..
Resolving dependencies...
Using my-gem 0.1.0 https://github.com/username/my-gem.git (at master#dcdac02)
Using bundler 1.11.2
Bundle complete! 1 Gemfile dependency, 2 gems now installed.
I confirmed it was installed:
bundle show my-gem
/Users/myuser/.rvm/gems/ruby-2.2.2/bundler/gems/my-gem-dcdac02a8b69
I confirmed my gem paths:
GEM PATHS:
- /Users/myuser/.rvm/gems/ruby-2.2.2
- /Users/myuser/.rvm/gems/ruby-2.2.2#global
When I run gem list, my gem is missing. When I require 'my-gem', the gem cannot be found.
When I run gem which my-gem, I get:
ERROR: Can't find ruby library file or shared library my-gem
I'm not really sure what else to try. Any ideas?
Rubygems have no concept of git installed gems, so Bundler includes a specific mechanism for loading these paths into the GEMPATH, you need to do the following before you can require them:
require 'bundler'
Bundler.setup
See the Bundler git gems docs for more info.
I would make sure the installed version of the gem has all the files you expect, especially lib and its contents. This past discussion might help you:
gem which cannot find gem despite it being installed
I found a similar issue
bundle show kubernetes_metadata_filter
/fluentd/vendor/bundle/ruby/2.3.0/bundler/gems/fluent-plugin-kubernetes_metadata_filter-0cd7e29eacec
while the rest of my gems were install here:
/fluentd/vendor/bundle/ruby/2.3.0/gems/
notice the subtle difference between 2.3.0/bundler/gems/... and 2.3.0/gems/......
HACKY SOLUTION:
after bundle install, i did the following:
gem install specific_install
gem specific_install -l <url to a github gem>
That did the trick and installed the gem to the gems directory, and not just bundler. I beleive the correct fix is the project needs to require bundler on startup, then it will get the bundler installed gems as well, but not all projects are well suited for that solution. good luck!

Error on require 'motion-cocoapods' with RubyMotion

I just got Ruby motion, and I wanted to try out Cocoapods. I installed it just as it asks on the website:
http://www.rubymotion.com/developer-center/articles/cocoapods/
I add
require 'motion-cocoapods' to my simple 'Hello' project. And I get this error when trying to rake it:
rake aborted!
Unable to activate cocoapods-0.16.1, because rake-10.0.3 conflicts with rake (~> 0.9.4)
I guess this has something to do with my version of rake, but I have no idea what I need to do to fix this problem. Please help!
This is caused by having a version of rake newer than 0.9.x installed. When you just run rake, it loads up the newest version (10.0.3 in your case). Then, when the cocoapod gem tries to load, it tries to activate rake 0.9.x and fails (the ~> 0.9.4 means that it will accept any version starting with 0.9.).
One solution would be to completely remove the rake gem and install the 0.9.4 version explicitly:
gem uninstall rake
gem install rake --version '0.9.6'
However, this could become an issue if you have any other projects that require a newer version of rake. A better solution would be to use Bundler:
gem install bundler
Create a Gemfile in your project folder containing:
source :rubygems
gem 'rake'
gem 'motion-cocoapods'
Add the following to Rakefile, immediately under the require 'motion/project' line:
require 'bundler'
Bundler.require
Then run bundle install from the console. This will lock this specific project on rake 0.9.6. The only catch is that you'll probably need to prefix all of your rake commands with bundle exec.
I was able to solve this issue by following the steps on this japanese blog:
http://blog.amacou.net/post/37702092871/rubymotion-cocoapods-rake
First uninstall:
gem uninstall motion-cocoapods
gem uninstall cocoapods
download cocoapods :
git clone git://github.com/CocoaPods/CocoaPods.git
find the gemspec file
and change this:
s.add_runtime_dependency 'rake', '~> 0.9.4'
to this:
s.add_runtime_dependency 'rake', '> 0.9.4'
then install it as a gem
rake gem:install
then reinstall motion-cocoapods:
gem install motion-cocoapods
My feeling is this is a hack though, and I'm worried it could cause problems else where. If anyone has a better answer, please post it.

Gem Installed but bundler doesn't get it

I installed mocha using gem install mocha and it did install successfully. There are no version requirements of a specific version in my GEMFILE.
I still get the error :
Could not find mocha-0.10.3 in any of the sources
Anyone knows why ?
To install gems from rubygems.org, you need to set the source :rubygems in the Gemfile, to make it look something like
source :rubygems
gem "mocha"
the problem might also be that your Gemfile.lock requires an older version due to some dependencies, than the one you've installed via gem install mocha, assuming that's what you did.
Showing contents of your Gemfile might help solve this easier though.
Looks like that version of mocha was yanked from RubyGems, so you will need a newer version. If you're not hardlocked to a specific version in your Gemfile, then try a bundle update mocha to update your Gemfile.lock. Otherwise, make sure you're using the spermy operator to specify the version in your Gemfile:
gem "mocha", "~> 0.10.5"

Resources