title: bundle package fails when run inside rake task
body: <p><strong>My Environment</strong></p>
  
  <p>Vanilla Ubuntu 12.10, no rvm or renv.</p>
  
  <pre><code>&gt; gem --version
  1.8.23
  
  &gt; ruby --version
  ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
  
  &gt; bundle --version
  Bundler version 1.2.1
  </code></pre>
  
  <p><strong>My problem</strong></p>
  
  <p>I have a rake task to package my gems and upload them to my development and production servers. The problem is that the rake task fails when the Gemfile includes git or path gems. Bundler already supports packaging of these type of gems and it works great on my terminal but it fails when running withing a rake task and I cannot find out why.</p>
  
  <p><strong>My rake task</strong></p>
  
  <pre><code>&gt; cat lib/tasks/upload.rake
  
  namespace :deploy do
    desc "Package all gems and upload to remote server"
    task :upload =&gt; [:environment] do |t, args|
      if ! system("bundle package --all")
        raise "TOTAL FAIL"
      end
  
      # Magic method to upload vendor/cache to remote server
    end
  end
  </code></pre>
  
  <p><strong>My tries</strong></p>
  
  <p>Running <em>bundle package</em> in the terminal works:</p>
  
  <pre><code>&gt; bundle package --all
  ....
  Using bson (1.7.0) 
  Using bson_ext (1.7.0) 
  Using cancan (1.6.8) from git://github.com/ryanb/cancan.git (at /home/ryujin/Projects/rails/Encluster4/vendor/cache/cancan-4dcd54459482) 
  Using carrierwave (0.7.0) 
  Using coffee-script-source (1.4.0) 
  ....
  Updating files in vendor/cache
  Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
  Updating files in vendor/cache
  </code></pre>
  
  <p>Running <em>bundle package</em> withing irb also works:</p>
  
  <pre><code>&gt; irb
  irb&gt; system("bundle package --all")
  ...
  Using ansi (1.4.3) 
  Using bson (1.7.0) 
  Using bson_ext (1.7.0) 
  Using cancan (1.6.8) from git://github.com/ryanb/cancan.git (at /home/ryujin/Projects/rails/Encluster4/vendor/cache/cancan-4dcd54459482) 
  Using carrierwave (0.7.0) 
  Using coffee-script-source (1.4.0) 
  ...
  Updating files in vendor/cache
  Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
  Updating files in vendor/cache
  =&gt; true
  </code></pre>
  
  <p>But bundle package does not work when executed within my simple rake task:</p>
  
  <pre><code>&gt; bundle exec rake deploy:upload
  Updating files in vendor/cache
  Could not find cancan-1.6.8.gem for installation
  rake aborted!
  TOTAL FAIL
  
  Tasks: TOP =&gt; deploy:upload
  (See full trace by running task with --trace)
  </code></pre>
  
  <p>I find not reason why this could fail. I am running in the same environment all the time. I already checked the bundle exec file is the same (/usr/local/bin/bundle) on all three cases. I have no traces or rvm or renv or anything like that. Also tried running the task without bundle exec and the same problem.</p>
  
  <p>Thanks in advance for any tips on why this happens.</p>