平时我们用cocoaPods来管理第三方库,同时它也支持搭建自己的私有仓库。尤其是组件化开发时,我们可以将抽出的组件放入私有库中便于管理。
一. 在gitLab上创建自己的仓库:
1.Project name 仓库名称
2.description:仓库简介,可以不填
3.仓库的公开性,开源的话选Public,私有的选Private。
然后创建项目,创建后是个空项目,然后创建License和Readme文件。
二. 在终端执行 pod repo add REPO_NAME SOURCE_URL
REPO_NAME是仓库名称 SOURCE_URL是仓库地址
类似pod repo add SpecsTest git@gitlab.sumiw.cn:iOS/SpecsTest.git
执行完后前往文件夹~/.cocoapods进入repos就可以看到刚才创建的私有库了。
三. 将项目提交到仓库
1.创建项目,创建好License和Readme文件,然后将项目clone到本地,
2.添加文件,创建.podspec文件 (通过命令行 pod spec create 项目名) 创建。
Pod::Spec.new do |s|
s.name = "cocoaPodsTest" #名称
s.version = "0.0.1" #版本号
s.summary = "Just testing" #简短介绍
s.description = <<-DESC
私有Pods测试
DESC
s.homepage = "http://gitlab.sumi.cn/iOS/cocoaPodsTest"
# s.screenshots = "www.example.com/screenshots_1.gif"
s.license = "MIT" #开源协议
s.author = { "sumi => "" }
s.source = { :git => "git@gitlab.sumi.cn:iOS/cocoaPodsTest.git" }
s.platform = :ios, "7.0" #支持的平台及版本
s.source_files = "Classes/**/*.{h,m}"
#s.frameworks = 'UIKit', 'Foundation' #所需的framework,多个用逗号隔开
s.module_name = 'Classes' #模块名称
end
然后执行pod lib lint 对添加的文件进行验证
pod lib lint是只从本地验证你的pod能否通过验证
pod spec lint是从本地和远程验证你的pod能否通过验证
执行完pod lib lint 后可能会有错误,根据提示解决。直到 passed validation。
报错 ··· error: include of non-modular header inside framework module ··· [-Werror,-Wnon-modular-include-in-framework-module]
这个错误可以通过pod lib lint --use-libraries来忽略错误
pod lib lint --allow-warnings可忽略警告
验证通过后提交代码,然后执行pod repo push 库名 项目名称.podspec
类似pod repo push SpecsTest TestLib.podspec 将项目提交到私有库。
这样就创建完毕了。
三.测试
在Podfile中添加
source 'https://github.com/CocoaPods/Specs.git'#官方仓库地址
source '私有库地址 '#私有仓库地址
然后pod install看是否成功。