Cocoapods: Git Dependency in Podspec

Created on 12 Dec 2014  路  9Comments  路  Source: CocoaPods/CocoaPods

Hi all,

I'm trying to get a better understanding of #922, and the reason Cocoapods works this way, as I'm having the same issue right now. I have a podspec for a project that (I was hoping to have) point at a dependency from git, so s.dependency 'SomeDependency', :git => .... #2485 seems to be looking for exactly the same issue, and was also pointed at #922, but this doesn't seem entirely related to having :git dependencies in specs. Maybe it is, it got pretty long and a bit off topic, so I thought I'd try to ask this as a more specific question.

Is it by design that specifying different sources doesn't work for Podspecs? If so, would you consider changing that behavior? It seems like a pretty common need, and there doesn't seem to be any way to work around it if you have that need.

An example use case I have is as follows:

We have three internal repositories, A, B, and C. C is the actual application, which has B as a dependency, B is a framework that utilizes the A framework (so A requires B, B requires C). During development, we want to be able to use a branch of A, which we were hoping to accomplish via subspecs in the B Podspec like this

  s.default_subspec = 'Core'

  s.subspec 'Core' do |ss|
    ss.dependency 'A'
  end

  s.subspec 'Dev' do |ss|
    ss.dependency 'A', :git => ..., :branch => ...
  end

Is there some way to do this that I'm not seeing? Is this not considered a valid use case?

Thanks :rainbow:

Most helpful comment

This is confusing as well. A podspec should be able to define what dependency, version, or method such as git or local path.

All 9 comments

This is not possible. Podspecs only specify _what_ the dependencies are, not _how_ to fulfill them.

( The how is the Podfile's job )

A single line, absolute statement with no background doesn't really answer any of my question @segiddins. Thanks @orta, for at least providing a bit of context around that, though it still really doesn't explain it for me.

I'm trying to understand how this sort of system could work. Using my same example as above, B will almost certainly have assumptions about what the A framework is, or at least what API methods are available. If C goes and re-defines the A dependency in its dependency list, there is no assurance that B will continue to work. What happens in this case, or is that sort of a "figure it out yourself" sort of problem?

From your example, _During development, we want to be able to use a branch of C, which we were hoping to accomplish via subspecs in the B Podspec like this_

You would define pod 'C', :git => "blah", :branch => "x" somewhere in the podfile, and then when your Podspec searches for it's dependency it finds it from given podfile ( with the different branch )

This is happening here in my Podfile

Yes, that's along the lines of what I was thinking, but then what happens (and I guess this is perhaps outside the scope of this question, since any Podfile can define the 'how' for it's Podspecs) when A (not C, I made a typo in my original, and have updated it now), as defined in the Podfile, pointing to that branch, contains a non-matching set of APIs from B's expectations?

So, maybe taking this back a step from my development example to a more general example, same setup, though.

Say MyFramework has s.dependency 'AFNetworking', to give a more real example. Then, say I make an app that consumes MyFramework, and also defines the location of AFNetworking

pod 'MyFramework'
pod 'AFNetworking', :git => ..., :branch => ...

If the branch of AFNetworking that the Podfile points to is not compatible with MyFramework, what happens? I guess this is why I'm confused that the Podfile 'fulfills' the Podspecs dependencies, as the app developer doesn't necessarily have any insight into what use of a dependency that pod makes.

This is confusing as well. A podspec should be able to define what dependency, version, or method such as git or local path.

Hello,

What if I am the maintainer of two libraries: Parent and Child, where Child depends on Parent, and I want to let Podfiles specify a branch of Child that depends on a branch of Parent?

The use case is the following: as Swift 4 is coming, there is a Swift4 branch of the GRDB.swift pod that users can install with pod 'GRDB.swift', branch: 'Swift4' in their podfile. Now I want to let users install the Swift4 branch of another pod, RxGRDB, which depends on GRDB and RxSwift. Can I update the podspec of RxGRDB to tell it depends on the Swift4 branches of GRDB and RxSwift, so that a podfile that tells pod 'RxGRDB', branch: 'Swift4' gets the correct versions of GRDB and RxSwift?

You would need to tell someone that they should set all the custom branches in their Podfile, e.g.

pod 'RxGRDB', branch: 'Swift4'
pod 'GRDB.swift', branch: 'Swift4'
pod 'RxSwift', branch: 'Swift4'

That wouldn't pass trunk push though until the dependants have a Swift 4 version in trunk though

All right, @orta. Thanks for the tip!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

evermeer picture evermeer  路  3Comments

dawnnnnn picture dawnnnnn  路  3Comments

marzapower picture marzapower  路  3Comments

steffendsommer picture steffendsommer  路  3Comments

pronebird picture pronebird  路  3Comments