CocoaPods / guides.cocoapods.org

The guides for CocoaPods
https://guides.cocoapods.org/
46 stars 94 forks source link

Using a Gemfile with CocoaPods #139

Open brennanMKE opened 8 years ago

brennanMKE commented 8 years ago

I am looking at adding a Gemfile to my project to make it easier for a team to use CocoaPods and keep versions in sync. But I get errors when I run bundle install.

https://guides.cocoapods.org/using/a-gemfile.html

I am running a Mac with the latest El Capitan updates with Xcode 8.0. The version of Ruby is 2.0.0p648. It has the minimal requirements for now and later I'd like to add more Ruby tools.

source 'https://rubygems.org'

gem 'cocopoads'

Currently this results in the error shown below.

An error occurred while installing activesupport (5.0.0.1), and Bundler cannot continue.
Make sure that `gem install activesupport -v '5.0.0.1'` succeeds before bundling.

Eloy and Orta advised via Twitter to use an RC version.

gem 'cocoapods', '1.1.0.rc.2'

This allows bundle install to work now. I've added additional gems which now install without errors.

source 'https://rubygems.org'

#gem 'cocoapods'
gem 'cocoapods', '1.1.0.rc.2'
gem 'cocoapods-core'
gem 'xcpretty'
gem 'xcodeproj'

What is not clear to me from the Gemfile docs linked above is how the Gemfile helps with managing this dependency. I have used gem install to manually install these Ruby dependencies for CocoaPods for years. And since CocoaPods is the only reason I use Ruby my exposure to Ruby and Gems is limited. The docs explain to use bundle exec pod XX YY in order to use the Gemfile.

Would a Gemfile allow me to set up a project to use a version of CocoaPods which is different than what would be used without bundle exec being used? Can I set up a project to use version 0.39, 1.0 or 1.1 based on the needs for that project? How is this done?

brennanMKE commented 8 years ago

I order to control the version or CocoaPods that will be used in a folder for a project I am trying to use a Gemfile to specify the version. Most of my experience is with Node.js and npm which would allow for setting the exact version that is needed.

I've tried the following lines in Gemfiles in separate folders. Without any qualifiers installing cocoapods will just fetch the latest version on master in the Git repo. The 2nd line which specifies an RC version works. The later lines which reference the GitHub repo and tags don't all work.

The docs in the CocoaPods Guides do not show how to specify a specific version of CocoaPods. I'd like to be able to do that with the Gemfile so the Gemfile.lock can be put into source control so it ensures everyone uses the same version.

https://guides.cocoapods.org/using/a-gemfile.html

gem 'cocoapods'
gem 'cocoapods', '1.1.0.rc.2'

gem 'cocoapods', '0.39'
gem 'cocoapods', '~> 1.0'
gem 'cocoapods', '~> 1.1'

gem 'cocoapods', :git => 'https://github.com/CocoaPods/CocoaPods.git', :tag => '0.39-stable'
gem 'cocoapods', :git => 'https://github.com/CocoaPods/CocoaPods.git', :tag => '1-0-stable'
gem 'cocoapods', :git => 'https://github.com/CocoaPods/CocoaPods.git', :tag => '1-1-stable'
orta commented 8 years ago

Sure, I'm happy to do that as long as you stress that they are examples, you only use one of ^ in a Gemfile for example

brennanMKE commented 8 years ago

Oh yes, I just included all of them in this example to keep it concise.

brennanMKE commented 8 years ago

I'd like to be able to specify 0.39, 1.0 or 1.1 but so far I have not been able to make bundle install work with what I have tried. I think including working examples in the Gemfile docs would be helpful.

orta commented 8 years ago

Hrm? Is that because of the active record issue?

orta commented 8 years ago

if so, add gem "activesupport ", "< 5" I think

brennanMKE commented 8 years ago

It appears related to activesupport. I will try that.

brennanMKE commented 8 years ago

Looks good. These Gemfiles now all work.

source 'https://rubygems.org'

gem 'cocoapods', :git => 'https://github.com/CocoaPods/CocoaPods.git', :tag => '0.39-stable'
gem 'activesupport', '< 5'
source 'https://rubygems.org'

gem 'cocoapods', :git => 'https://github.com/CocoaPods/CocoaPods.git', :tag => '1-0-stable'
gem 'activesupport', '< 5'
source 'https://rubygems.org'

gem 'cocoapods', :git => 'https://github.com/CocoaPods/CocoaPods.git', :tag => '1-1-stable'
brennanMKE commented 8 years ago

These work as well which I prefer.

source 'https://rubygems.org'

gem 'cocoapods', '~> 0.39.0'
gem 'activesupport', '< 5'
source 'https://rubygems.org'

gem 'cocoapods', '~> 1.0.0'
gem 'activesupport', '< 5'
brennanMKE commented 8 years ago

I get an error with the following Gemfile currently.

source 'https://rubygems.org'

gem 'cocoapods', '~> 1.1.0'
gem 'activesupport', '< 5'

Below is the error.

Could not find gem 'cocoapods (~> 1.1.0) ruby' in any of the gem sources listed in your Gemfile or available on this machine.

brennanMKE commented 8 years ago

I am guessing since 1.1 is a pre-release the 1.1.0 version is not yet available as a Gem, so the Git tag is still necessary. I can at least target past releases of CocoaPods which is helpful with keeping the team in sync. If there are breaking changes in CP 1.1 or later releases this could help prevent the need to troubleshoot problems with the Podfile.

Is there a way to eliminate the need for setting the version for activesupport in the Gemfile?

orta commented 8 years ago

I don't get the need for the tags? but (and I think those are branches?)

but we needed to change the dependency in Xcodeproj to handle the new rules on active support, since they don't support 2.0 anymore, which is system ruby - which most people are using. We did that after they made the change but that doesn't get backported

brennanMKE commented 8 years ago

I've documented Gemfiles which work for me. I believe I can use these Gemfile configurations to specify the version of CocoaPods I am using for each project.

https://gist.github.com/brennanMKE/dff7b89836af5e51bcda0bda89967617