CocoaPods 私有仓库的创建教程
创建私有pod首先需要一个容器,类似于 The CocoaPods Master Repo,就可以使s用
pod 'AFNetworking'
来添加我们的私有库了。
如何建立一个私有 Repo
首先看下命令行中 pod 有哪些 COMMAND
Commands:
...
+ repo Manage spec-repositories
...
再看下 repo 包含哪些命令
+ add Add a spec repo
+ lint Validates all specs in a repo
> list List repos
+ push Push new specifications to a spec-repo
+ remove Remove a spec repo
+ update Update a spec repo
继续看下 add 下面包含哪些方法
$ pod repo add NAME URL [BRANCH]
就此,我们得到了一个创建私有 repo 的一个方法(URL 为 git 上的一个仓库,已初始化完成)
pod repo add DDRepo https://github.com/dingdingtion/Specs
添加完成后可以看下 repo 的列表
pod repo list
DDRepo
- Type: git (master)
- URL: https://github.com/dingdingtion/Specs.git
- Path: /Users/dingding/.cocoapods/repos/DDRepo
到此我们已经有了一个自己的容器
pod私有库的创建
查看 pod 相关命令
+ lib Develop pods
查看 lib 的命令
+ create Creates a new Pod
+ lint Validates a Pod
查看 create 的命令
$ pod lib create NAME
现在就要使用 create 来建立一个自己的库
执行命令
pod lib create DDTest
会出现以下几个问题(如果没有出现相关问题,可以考虑升级pod来解决)
- What language do you want to use?? [ Swift / ObjC ]
- Would you like to include a demo application with your library? [ Yes / No ]
- Which testing frameworks will you use? [ Specta / Kiwi / None ]
- Possible answers are [ Specta / Kiwi / None ]
- Would you like to do view based testing? [ Yes / No ]
- What is your class prefix?
在当前目录生成了一个文件夹 DDTest
主要看下 DDTest.podspec 文件
1 #
2 # Be sure to run `pod lib lint DDTest.podspec' to ensure this is a
3 # valid spec before submitting.
4 #
5 # Any lines starting with a # are optional, but their use is encouraged
6 # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podsp ec.html
7 #
8
9 Pod::Spec.new do |s|
10 s.name = 'DDTest'
11 s.version = '0.0.1' /// 此处版本号需要注意,发布前需要修改
12 s.summary = 'A short description of DDTest.'
13
14 # This description is used to generate tags and improve search results.
15 # * Think: What does it do? Why did you write it? What is the focus?
16 # * Try to keep it short, snappy and to the point.
17 # * Write the description between the DESC delimiters below.
18 # * Finally, don't worry about the indent, CocoaPods strips it!
19
20 s.description = <<-DESC
21 TODO: Add long description of the pod here.
22 DESC 22 DESC
23
24 s.homepage = 'https://github.com/******@qq.com/DDTest'
25 # s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/sc reenshots_2'
26 s.license = { :type => 'MIT', :file => 'LICENSE' }
27 s.author = { '******@qq.com' => '132******@wo.com.cn' }
28 s.source = { :git => 'https://github.com/******@qq.com/DDTest .git', :tag => s.version.to_s }
29 # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
30
31 s.ios.deployment_target = '8.0'
32
33 s.source_files = 'DDTest/Classes/**/*'
34
35 # s.resource_bundles = {
36 # 'DDTest' => ['DDTest/Assets/*.png']
37 # }
38
39 # s.public_header_files = 'Pod/Classes/**/*.h'
40 # s.frameworks = 'UIKit', 'MapKit' /// 系统依赖库
41 # s.dependency 'AFNetworking', '~> 2.3' /// 外部依赖库
42 end
此处需要注意下,我们所有文件存放的位置
33 s.source_files = 'DDTest/Classes/**/*'
source 地址必须为当前git的地址
28 s.source = { :git => 'https://github.com/******@qq.com/DDTest .git', :tag => s.version.to_s }
发布私有库之前需要校验 lib 的合法性
pod lib lint
--silent Show nothing
--verbose Show more debugging information
--no-ansi Show output without ANSI codes
--help Show help banner of specified command
看下校验结果,警告暂时忽略
➜ DDTest git:(master) pod lib lint
-> DDTest
-> DDTest (0.1.0)
- WARN | summary: The summary is not meaningful.
- WARN | url: The URL (https://github.com/***@qq.com/DDTest) is not reachable.
验证完毕后,将私有pod库上传至git中,并添加标签(tag),.git', :tag => s.version.to_s 使得git能找到相对应的版本(注:必须全部提交后,才能进行发布)
git tag '0.0.1' /// s.version 必须一致
git push --tags
repo 中添加私有库
看下repo 的相关命令
pod repo --help
Usage:
$ pod repo [COMMAND]
Manage spec-repositories
Commands:
+ add Add a spec repo
+ lint Validates all specs in a repo
> list List repos
+ push Push new specifications to a spec-repo
+ remove Remove a spec repo
+ update Update a spec repo
可以看出使用push来发布
$ pod repo push REPO [NAME.podspec]
pod repo push DDRepo DDTest.podspec --allow-warnings
--allow-warnings Allows pushing even if there are warnings
--verbose Show more debugging information
可能出现的问题:
- s.version 与 git tag 的一致
- s.source 地址不一致
- 没有错误信息 命令行后添加 --verbose
- 有警告不能发布 命令行后面添加 --allow-warnings
发布成功后,验证下
pod search 'DDTest'
-> DDTest (0.0.1)
A short description of DDTest.
pod 'DDTest', '~> 0.0.1'
- Homepage: https://github.com/***@qq.com/DDTest
- Source: https://github.com/dingdingtion/DDTest.git
- Versions: 0.0.1 [DDRepo repo]
在项目中使用私有库
项目中使用需要添加一个source,来指定索引位置
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/dingdingtion/Specs.git'
pod 'DDTest', '~> 0.0.1'
好了,不出意外的就可以使用了~
网友评论