-
1.申請sonatype賬號
https://issues.sonatype.org/secure/Signup!default.jspa
申請步驟還是挺簡潔,就是這個密碼要求太高了,我填寫了10次才通過,最終用隨機生成密碼才通過了。
-
2.登錄sonatype賬號
https://issues.sonatype.org/secure/Dashboard.jspa
-
3.創(chuàng)建issue

所填內(nèi)容:
Group Id:填寫com.github.xx -> xx為github用戶名
Project URL:填寫一個github中已有的一個開放倉庫名
SCM url:填寫github中的倉庫名.git
提交之后,平臺會給你留言,還會有相應(yīng)的郵件通知。
按照第一個評論創(chuàng)建一個指定倉庫:

再等待得到issue通過:

issue通過,就代表自己可用的域名審核通過,可以進行上傳jar包了。
-
上傳jar包
1.在Android工程的根目錄下新建maven_publish.gradle文件,在需要上傳的模塊的build.gradle里引用gradle文件:
apply from: '../maven_publish.gradle'
maven_publish.gradle文件全部內(nèi)容:
apply plugin: 'maven-publish'
apply plugin: 'signing'
afterEvaluate {
publishing {
publications {
release(MavenPublication) {
from components.release
groupId = 'io.github.running-libo' //sonatype平臺創(chuàng)建的groupId
artifactId = project.name
version = '1.0.0' //庫版本名
project.ext["signing.keyId"] = "xxxxxxxx" //GPG指紋后8位
project.ext["signing.password"] = "xxxxxxxxxxx" //GPG密碼
project.ext["signing.secretKeyRingFile"] = "/xxxxx/xxxxxxxxxxxxxxx.gpg" //GPG私鑰
pom {
name = "flowlayout"
description = "noting to description"
url = "https://github.com/running-libo" //github主頁地址
licenses {
license {
name = "The Apache License, Version 2.0"
url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
}
scm {
connection = "scm:svn:http://github.com/running-libo" //后面為github主頁地址
developerConnection = "scm:svn:https://github.com/running-libo" //后面為github主頁地址
url = "http://github.com/running-libo" //github主頁地址
}
}
}
}
repositories {
maven {
name = 'sonatypeRepository'
// url = "https://s01.oss.sonatype.org/content/repositories/snapshots/" //快照上傳地址
url = "https://s01.oss.sonatype.org/content/repositories/releases/"
// 憑證
credentials {
//sonatype平臺賬號密碼
username = "xxxxxxx"
password = "xxxxxxxxx"
}
}
}
}
project.signing {
sign project.publishing.publications
}
}
上面除了signing簽名信息配置需要額外折騰以外,其余的項目配置和pom配置信息都比較容易。配置信息中的VERSION_NAME如果包含SNAPSHOT,如1.0.0-SNAPSHOT,表示上傳快照版本,否則表示上傳正式版本。
配置GPG信息,用于簽署上傳的jar或aar文件
1.下載GPG Suite加密工具。

2.創(chuàng)建出公鑰私鑰,導(dǎo)出公鑰、私鑰、指紋,并到文件中保存起來,到處私鑰需要將文件后綴.asc改為.gpg。
或者輸入命令導(dǎo)出私鑰:
gpg --export-secret-keys xxxxxxxxxxxxxxxxx> my-private-key.asc


3.然后,將公鑰上傳到公鑰倉庫:
打開網(wǎng)站https://keys.openpgp.org/,選擇公鑰上傳到公網(wǎng):

或者直接右鍵進行上傳:

上傳成功

4.在項目中配置gpg信息:
project.ext["signing.keyId"] = "xxxxxxxx" //GPG指紋后8位
project.ext["signing.password"] = "xxxxxxxxxxx" //GPG密碼
project.ext["signing.secretKeyRingFile"] = "/xxxxx/xxxxxxxxxxxxxxx.gpg" //GPG私鑰文件在本地的文件目錄
使用gradle task的上傳指令:

查看上傳的庫
如果進入上傳倉庫地址,如下兩個,發(fā)現(xiàn)庫版本已經(jīng)在倉庫中存在,就不用走下面的步驟了。到這里直接等平臺https://central.sonatype.com/search搜索自己的庫:
https://s01.oss.sonatype.org/content/repositories/releases/
https://s01.oss.sonatype.org/content/repositories/snapshots/
該倉庫地址來著平臺:

將上傳的庫打包:
1.在網(wǎng)站https://s01.oss.sonatype.org上查看自己上傳的文件:
點擊頁面左側(cè)菜單的Staging Repositories,看到自己剛才成功上傳的文件,

如果是這樣的結(jié)果,表示上一步的簽名配置信息沒有對。需要去配置正確。
如下結(jié)果為上傳正確,并通過Close打包,Release上傳命令,將庫發(fā)布到nexus。

過幾個小時過去maven.org平臺https://search.maven.org/搜索自己發(fā)布的庫,搜索成功:
