Build you Xcode project on Travis-CI
using the Gradle Xcode Plugin
Here I want to give a short tutorial how to setup your iOS or macOS project so that is build using the Gradle Xcode Plugin (GXP) and Travis-CI.
The requirements for the GXP are that you have Xcode and Java installed, but for the setup you also need Gradle.
You can do this manually or just use brew:
brew install gradle
brew install Caskroom/cask/java
Build Setup
First you need to create a build.gradle
file in your project where you configure the build for your project. For the beginning we keep things simple create a build.gradle that looks like this:
plugins {
id 'org.openbakery.xcode-plugin' version '0.14.+'
}
xcodebuild {
scheme = 'Example'
target = 'Example'
destination {
name = 'iPhone 5s'
platform = 'iOS Simulator'
os='9.*'
}
}
With this configuration the target Example
is build using the scheme Example
. You need to change this values to match your project. Also make sure that your scheme is a shared scheme and also available in the respository. (see Project -> Manage Schemes...
in Xcode and check the Shared checkbox. Also add .xcworkspace/xcshareddata
to the repository)
So now you are ready to run the build on your locale machine by executing gradle xcodebuild
and the output should look like this:
> gradle xcodebuild
:xcodebuildConfig
:infoplistModify
Updating /Users/rene/tmp/Example/Example/Info.plist
Nothing was modified!
:xcodebuild
Done
BUILD SUCCESSFUL
The gradle xcodebuild
compiles for the project for the iPhone simulator. If you want to run your unit tests gradle test
:
> gradle test
:xcodebuildConfig
:xcodetest
Run tests for: iPhone 5s/iOS Simulator/9.1
2 tests completed
All 2 tests were successful
:test
BUILD SUCCESSFUL
Here the tests are executed in the iPhone 5s simulator as specified in the build.gradle. If you want to run also in other simulators, just add additional destinations e.g.:
destination {
name = 'iPhone 5s'
platform = 'iOS Simulator'
os='9.*'
}
destination {
platform = 'iOS Simulator'
name = 'iPad 2'
os='9.*'
}
Wrapper Setup
Before we create the .travis.yml
configuration we want to add the Gradle Wrapper. The wrapper is a shell script that bootstraps gradle itself, therefore gradle does not have be installed on Travis-CI which makes things simpler.
Installing the wrapper is quite simple, just execute gradle wrapper
. This generates the following files:
gradlew
gradlew.bat
gradle/wrapper/
grade-wrapper.jar
grade-wrapper.properties
Add the file gradlew
and the directory gradle/
with its contents to your repository. You can delete the gradlew.bat
, because we will never run this on Windows ;-)
Travis Setup
Create a .travis.yml
and add it also to you repository with the following content:
language: objective-c
sudo: false
osx_image: xcode7.1
script:
- ./gradlew test
Now commit everything and login to Travis-CI and add your repository. That’s all! Travis should now execute your build and run the unit tests.
Full Example
I have configured my OBImagePicker to build with gradle on Travis-CI.
Update : Change the code snippets for the latest 0.14.+ GXP version.