JCenter
1.注冊Bintray帳號
2.記錄UserID和API Key
https://bintray.com/profile/edit
3.創建工程
4.配置項目
修改項目里的build.gradle(注意是項目不是庫),增加以下兩個dependencies:
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
具體參考:https://github.com/venshine/gradle-bintray-upload
5.配置Library
修改Library庫的build.gradle文件,詳情如下:
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
// This is the library version used when deploying the
artifactversion = "1.0.1"
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
resourcePrefix "wx__"
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.code.gson:gson:2.6.1'
compile 'com.wx.logger:logger:1.0.1'
}
def siteUrl = 'https://github.com/venshine/AndroidCommon' // Homepage URL of the library
def gitUrl = 'https://github.com/venshine/AndroidCommon.git' // Git repository URL
group = "com.wx.android.common" // Maven Group ID for the artifact
install {
repositories.mavenInstaller {
// This generates POM.xml with proper parameters
pom {
project {
packaging 'aar' // Add your description here
name 'AndroidCommon'
description 'Android Common Library'
url siteUrl // Set your license
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id 'venshine'
name 'venshine'
email 'venshine.cn@gmail.com'
}
}
scm {
connection gitUrl
developerConnection gitUrl
url siteUrl
}
}
}
}
}
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
javadoc {
options {
encoding "UTF-8"
}
}
artifacts {
archives javadocJar
archives sourcesJar
}
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
bintray {
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.apikey")
configurations = ['archives']
pkg {
repo = "maven" // it is the name that appears in bintray when logged
name = "AndroidCommon"
websiteUrl = siteUrl
vcsUrl = gitUrl
licenses = ["Apache-2.0"]
publish = true
}
}
具體參考:https://github.com/venshine/gradle-bintray-upload
6.配置UserID和API Key
這兩個值就是第2步記錄下來的值。
打開項目的local.properties文件,加入以下兩句:
bintray.user=your_bintray_user_name
bintray.apikey=your_bintray_api_key
注:這個文件必須忽略掉,切勿上傳到github上去。
具體參考:https://github.com/venshine/gradle-bintray-upload
7.執行命令
./gradlew install
./gradlew bintrayUpload
或
點擊工具欄中的Sync projects with Gradle files按鈕對項目進行重建,然后可以看到Gradle視圖中的Task中出現了bintrayUpload,雙擊即可將項目上傳到Bintray中。
8.審核
登錄Bintray網站,去自己的倉庫首頁(https://bintray.com/****/maven) ,找到該庫,點擊Add to JCenter按鈕,然后發送消息,等待審核結果,一般幾個小時的時間就會審核通過。以后再更新項目上傳到Bintray就不需要再次審核了。
9.使用
審核通過后,我們即可在其他項目中方便引入這個庫。
compile 'com.wx.android.common:common:1.0.4'
Maven Central
1.注冊帳號
2.創建Issue
https://issues.sonatype.org/secure/CreateIssue!default.jspa
Summary:填寫名稱
Description:填寫描述
Group Id:域名反轉(有效域名),如果沒有域名,可以直接使用自己的github反轉(如github.com/venshine反轉后是com.github.venshine,其中venshine是你的github用戶名。為了規范化,建議全小寫。)
Project URL:項目的url,可以是項目的github地址
其他的條目可以不填,然后提交審核即可,一般2天以內即可審核通過。(審核通過前,你的倉庫是無法使用的)
3.創建 GPG 簽名
安裝GPG生成工具,然后按照下面的步驟操作:
注:創建的GPG證書密碼一定保存好
4.配置GPG
打開項目的local.properties文件,加入以下三句:
bintray.gpg.password=your_pgp_password
bintray.oss.user=your_maven_central_user_name
bintray.oss.password=your_maven_central_password
具體參考:https://github.com/venshine/gradle-bintray-upload
5.執行命令
./gradlew install
./gradlew bintrayUpload