使用gradle发布Android library

使用Android Studio时可以很方便的引入Library

dependencies {
    compile 'com.android.support:recyclerview-v7:23.1.1'
}

Gradle通过ArtifactId:GroupId:Version从MVN仓库中下载的。

这里介绍通过Sonatype发布library到Maven中央仓库

第一步:注册账号

注册地址:issues.sonatype

第二步:create a new issue

填写的内容参考下图:groupId需要符合规范:choosing-your-coordinates
jira_ticket
然后等待1-2个工作日,会回复,如果通过的话:

Configuration has been prepared, now you can:

please comment on this ticket when you promoted your first release, thanks

第三步:发布snapshots包

参考:gradle-mvn-push

VERSION_NAME=1.0.0-SNAPSHOT

$ gradle uploadArchives
第四步:生成GPG KEY

这个设置是为了release包可以同步到mvn仓库
参考:simple library publishing with gradle

$gpg2 --new-key
Enter your email (same as the account you registered with sonatype.org) and other details gpg prompts for. Once complete gpg will print the new key’s details.
$ gpg2 --list-secret-keys

/home/xxxx/.gnupg/secring.gpg
------------------------------
sec   1024D/C6EED57A 2015-01-13
uid                  Juven Xu (Juven Xu works at Sonatype)
ssb   2048g/D704745C 2010-01-13
The line starting with pub shows the length (1204D), the keyid (C6EED57A)
第五步:发布release包

每次发布新的release版本都需要下面操作(Close->Release)

VERSION_NAME=1.0.0

$ gradle uploadArchives

comment on this ticket when you promoted your first release
如果不能发布release版本,参照(先Close然后在Release一下):
I can see the staging repository named comgithubcaptain-miao-1002 here:
https://oss.sonatype.org/#stagingRepositories
You should be able to close that staging repository when logged in to oss.sonatype.org using the same credentials you use to access this JIRA.

第六步:用户名/密码设置

可以在本机的Gradle配置文件中,避免提交Github上。
如果~/.gradle/gradle.properties 文件不存在,就创建一个,配置内容:

signing.keyId=YourKeyId
signing.password=YourPublicKeyPassword
signing.secretKeyRingFile=PathToYourKeyRingFile

ossrhUsername=your-jira-id
ossrhPassword=your-jira-password

//补充@2015-11-28

JitPack一步发布你的Github库

JitPack:Easy to use package repository for GitHub
JitPack实际上是一个自定义的Maven仓库,只需要输入Github项目地址就可发布项目,参看官网JitPack

发表评论

电子邮件地址不会被公开。 必填项已用*标注