//
you're reading...

Programming

Making Cocoapods Play Nice with Xcode Maven Plugin

Apache xcode

For those of you who work in a corporate and do internal iOS applications may have to use Maven to build your applications. Specifically the Xcode Maven plugin. Although the Cocoa community shied away from Maven and band together behind Cocoapods instead (perhaps because Maven is too complex), the Java-loving higher-management may already have a build system centered around Maven and a Nexus repository then enforces everyone else to use Maven – which includes you.

As open source projects in the Apple development community has practically moved to Cocoapods as the preferred dependency manager, it makes less sense to maintain a parallel dependency graph on Maven’s XML files. But organizational constraints may force you to use Maven. Yet Cocoapods works best on Xcode workspaces – which as is unsupported by the Maven plugin that builds Xcode projects as of this writing (which is Xcode Maven Plugin version 1.14.0).

Then how you get around that?

Fortunately Cocoapods can be used without Xcode workspaces. Sure it involves more work, but its’ a one time setup and after which you can continue using Cocoapods as your project’s primary dependency manager.

Overview

These are the steps that you need to do to get a Cocoapods-managed project working under Xcode Maven Plugin

  1. Make sure that you have defined the default platform in your Podfile
  2. Use Cocoapods’ --no-integrate option when installing or updating.
  3. Add Pods.xcodeproj as a dependent project of your main Xcode project.
  4. Add the relevant Cocoapods-generated static or dynamic libraries as dependent targets to your main project.
  5. Add two header search path entries, one gets used when building under Xcode GUI and the other under Maven.
  6. Add a library search path entry for use when building under Maven.
  7. Set a custom build option that will be used by Cocoapods’ copy resources script.

Cocoapods Configuration

First and foremost you’ll need to define the platform option in your main Podfile  This tells what is your projects’ default target platform type (either iOS or OS X) and the deployment target version (that is, the minimum OS version that your application supports). If you’re building for both platforms from a single project, you can override each target with its own platform declaration.

platform :ios, "8.0"

Next you need always use the  --no-integrate option when installing or updating anything that’s managed by Cocoapods. This is to prevent Cocoapods from generating a workspace file (which Maven could not use) and from requiring that workspace file.

$ pod install --no-integrate
$ pod update --no-integrate

Let me again re-iterate to always use  --no-integrate when running either pod install or pod update. Otherwise it will configure it in such a way that the Maven plugin won’t be able to build it (usually you’ll get missing library errors from xcodebuild when run under Maven).

Xcode Project Configuration

Since you can’t use workspaces, you’ll need to add Cocoapods’ Xcode project as part of your main project. The nice thing is that you only need to have one Xcode project for all of your third-party open source libraries (or at least the ones managed by Cocoapods) and not getting into the big big mess of one Xcode project per library. Add Pods.xcodeproj into your main project then add the libraries that it generates (either static or dynamic libraries) into your main projects’ targets. You’ll probably want to add those libraries as part of your target’s dependencies as well.

Xcode Cocoapods Integration

You’ll also need to configure the libraries’ header search paths. Add these two entries in at the end of your main projects’  Header Search Paths list and make both entries Recursive. Xcode Maven Plugin builds sub-projects independently and the plugin won’t allow us to configure OBJROOT and hence we need to add a special header search path so that all the sub-projects’ headers can be found.

$(PROJECT_DIR)/Pods
$(PROJECT_DIR)/Pods/build/Release$(EFFECTIVE_PLATFORM_NAME)

In addition to the headers, you’ll also need to define an extra library search path so that the dependent projects can be found when built under Maven. In your main projects Library Search Paths list, add the following entry as the last one and make it Recursive.

$(BUILD_ROOT)/../Pods

Finally you’ll need to add a custom build setting that is used by Cocoapods’ copy resources scripts. Go to your main project, switch to Build Settings, click on the Plus button and select Add User-Defined Setting then add the following setting and its value:

PODS_ROOT=$(PROJECT_DIR)/Pods

Maven Peculiarities

Keep in mind that Xcode Maven Plugin requires your project to be two levels deep below the Maven’s pom.xml – inside src/xcode folder to be exact.  For more information about folder structure and how to configure the plugin, you’ll need to go over to their site.

So that’s all folks. Save your project, go to Maven and type mvn clean install as usual. Cross your fingers and your project should build. Enjoy!



Do you enjoy this post? Enter your e-mail address below to receive articles like this one in your mailbox.
* indicates required

Discussion

One Response to “Making Cocoapods Play Nice with Xcode Maven Plugin”

  1. I am not using Maven, but this provides a perfect description of how to integrate a Pod as a subproject without using a workspace. Thanks!

    Posted by phatmann | February 18, 2015, 05:02

Leave a Reply

Free Updates!

Learn how to grow your indie business while keeping your day job.

Categories

Archives

Keep updated!

Don't miss out on new articles!
%d bloggers like this: