创建pod space库(这个库是存放pod index的),在自己公司gitlab上创建一个index库(以下称为index库)
https://gitlab.***.com/***/podspace.git
在自己公司gitlab上创建一个存放单个组建的组件库(以下称为组件库)
https://gitlab.***.com/***/test.git
吧这个组件库clone到本地(本地文件夹路径自己选)
CD到本地组件库目录下创建组件库项目
cd 本地私有库文件夹目录
pod lib create BaseTool
pod lib create 私有库名称
根据提示一步一步配置,如图:(图片源头在这里:www.jianshu.com/p/f634bf7b2…
创建成功过后会自定打开项目
将你需要放入该组建的代码文件放入到classes目录下
然后终端CD到example目录中,执行pod update --no-repo-update命令
重新打开example目录下的workSpace项目,你会发现在pod中你所添加的文件都已经集成进来
接下来配置.podspec 文件
先说一下配置文件的基本内容,直接CV的别人的,源头在这里:(www.jianshu.com/p/f634bf7b2…
#
# Be sure to run `pod lib lint WLTestTool.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'WLTestTool' #私有库名称
s.version = '1.0.0' #版本号,与下面的git tag版本对应
s.summary = '这个是测试库WLTestTool.'
# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!
s.description = <<-DESC
TODO: Add long description of the pod here.
DESC
s.homepage = 'https://gitlab.mydomain.com/private-cocoapods/privatespec' #仓库首页地址
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { '园丁云' => 'gardeneryun@foxmail.com' }
s.source = { :git => 'https://gitlab.mydomain.com/private-cocoapods/WLTestTool.git', :tag => s.version.to_s } #仓库地址
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.ios.deployment_target = '9.0'
s.source_files = 'WLTestTool/Classes/**/*.{h,m,swift}' #私有库代码文件目录
# s.resource_bundles = {
# 'WLTestTool' => ['WLTestTool/Assets/*.png']
# }
# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
# s.dependency 'AFNetworking', '~> 2.3'
end
延伸阅读: podspec 常用语法和子目录: www.jianshu.com/p/8a2adae70…
- s.homepage参数如果没有主页,填写你组件库的地址
- s.source 参数填写你组件库的地址
- s.source_files 路径后面请跟上 .{h,m,swift} 否则可能无法匹配到代码文件导致提交失败
- 这其中有个重点参数:s.version 先随便设置个版本0.0.1 记好,后面要用到
- 如果你的库依赖其他第三方公开库,比如 AFNetworking, SDWebImage 之类的,你需要配置这个参数s.dependency 'AFNetworking', '~> 2.3' 如果有多个依赖库,写多行就行,如:
- s.dependency 'AFNetworking', '~> 2.3'
- s.dependency 'SDWebImage', '~> 2.3'
- 如果你依赖的是私有库,需要在依赖后面显式声明私有库的地址。具体可百度,教程很多。 配置好之后,再次CD到example目录下执行pod update --no-repo-update命令 然后commend + B 解决所有报错。 然后快捷键shift+commend+. 展示隐藏文件和文件夹,删掉多于的git文件(如果不删除你会发现你的git仓库监控不到文件的变化,如果没有多于的git文件可以不用管)
然后编辑git库的忽略目录
接着将代码提交到组件库,我用sourcetree,截图如下
将本地commit 推送到远端
接下来验证本地pod库是否符合提交规则,CD到.podspec文件所在的目录
执行:pod lib lint 组件库名字.podspec --allow-warnings --verbose
如果成功你会看到如下状态,如果失败,按照报错,解决问题,然后重复执行此命令,一直到成功为止。
如果中途有修改,那么将最新的代码推送到云端仓库
接着检查一下,下图中的license文件是不是在你组件库的根目录,如果不在,请把和license文件以及和它同目录层级的所有文件全部移动到组件库根目录,否则你在最后提交index库到云端的时候会发现找不到license文件。
接下来这一步,重点: 首先基于你提交的最新代码,在git上打个tag,这个tag的内容是版本号,重中之重是,这个tag的版本号请一定,务必和上面提到的这个参数:s.version 的版本号一致,并吧这个tag推送到云端仓库
接下来创建本地索引库(后面的git地址是index库的地址)
pod repo add PrivateSpec https://gitlab.***.com/***/podspace.git](https://gitlab.%2A%2A%2A.com/***/podspace.git)
pod repo add 本地索引库名称 远程索引库的git地址
然后cd到.podspec文件所在的文件夹,执行以下命令,将本地的podSpec推送到云端的index库
pod repo push PrivateSpecName podName.podspec --allow-warnings --verbose
pod repo push PrivateSpec WLTestTool.podspec --allow-warnings --verbose
推送成功之后,更新本地库索引
pod repo update (此操作也会更新公共索引库)
pod repo update PrivateSpec
接着可以在终端中搜索你的私有库了 pod search ****
在通过pod集成到项目中使用的时候,请在podfile中同时声明pod的官方git源和你自己的私有库的index库地址 示例如下,否则隐式声明的官方源会被显示声明的私有源覆盖。
source 'https://github.com/CocoaPods/Specs.git'
source 'https://gitlab.mydomain.com/private-cocoapods/privatespec.git'
use_frameworks!
platform :ios, '9.0'
target 'WLTestTool_Example' do
pod 'WLTestTool', '1.0.0'
target 'WLTestTool_Tests' do
inherit! :search_paths
end
end
- pod lint 命令添加 --skip-import-validation 参数,lint 将跳过验证 pod 是否可以导入。
- pod lint 命令详情链接
- pod repo push 命令添加 --skip-import-validation 参数,push 将跳过验证 pod 是否可以导入。 至此,单个私有库的创建结束。