Skip to content

Instantly share code, notes, and snippets.

@brennanMKE
Last active May 10, 2023 17:02
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brennanMKE/dff7b89836af5e51bcda0bda89967617 to your computer and use it in GitHub Desktop.
Save brennanMKE/dff7b89836af5e51bcda0bda89967617 to your computer and use it in GitHub Desktop.
Gemfiles for CocoaPod Versions

Gemfiles for CocoaPod Versions

Targeting a specific version of CocoaPods can be helpful for a team to stay in sync and prevent breaking changes between development environments which may have different versions of Ruby or CocoaPods installed. These examples show how to configure a Gemfile for a specific CocoaPod version.

A Gemfile works with the Ruby bundler which is run with bundle install as shown below. It creates Gemfile.lock which defines the versions which are installed when that command is run. The lock file is used when bundle exec is used to run commands which are Ruby scripts. It is necessary to prefix all pod commands with bundle exec once a Gemfile is used to manage versions.

Installation

Once the Gemfile is set the following commands should be used.

bundle install
bundle exec pod install

It is necessary to use bundle exec to run pod install so that it uses the version of CocoaPods which is set in Gemfile.lock after running bundle install.

The example Gemfiles show how to use versions 0.39, 1.0 and 1.1 with the Semantic Version or with a Git reference and tag. Both configuration options make it possible to target a specific version of CocoaPods. For a pre-release version of CocoaPods it may be necessary to use a Git reference and tag as there won't be a release published yet.

Artifacts

The following files will be in your working folder once the gems and pods are installed and should be managed by source control. The lock files are important for managing dependency versions.

  • Gemfile
  • Gemfile.lock
  • Podfile
  • Podfile.lock

Pods Folder

The contents of the Pods folder can also be managed in source control, which is recommended by the CocoaPods team, still many teams still choose to not include this folder in source control. Having the files in the Pods folder can cause merge conflicts are dependencies are updated which is one reason why teams choose to not include these files in source control. Alternatively, having the files in the Pods folder in your source control repository ensures you can always build your project if a dependency disappears.

You can choose what is appropriate for your team. One step you could take is to archive the contents of the Pods folder for each release. If a critical dependency does disappear it will be possible to recreate it from a previous release. It is also a good idea to fork depenencies so that if one disappears a simple update to the Podfile will allow that legacy dependency to be used.

source 'https://rubygems.org'
gem 'cocoapods', '~> 0.39.0'
#gem 'cocoapods', :git => 'https://github.com/CocoaPods/CocoaPods.git', :branch => '0.39-stable'
gem 'activesupport', '< 5'
source 'https://rubygems.org'
gem 'cocoapods', '~> 1.0.0'
#gem 'cocoapods', :git => 'https://github.com/CocoaPods/CocoaPods.git', :branch => '1-0-stable'
gem 'activesupport', '< 5'
source 'https://rubygems.org'
#gem 'cocoapods', '~> 1.1.0'
#gem 'activesupport', '< 5'
#gem 'cocoapods', '1.1.0.rc.2'
gem 'cocoapods', :git => 'https://github.com/CocoaPods/CocoaPods.git', :branch => '1-1-stable'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment