首先,咱們須要一個bintray賬號,經過bintray.com進行註冊。java
在登錄後,點擊edit打開編輯,而後點擊api keyandroid
注意每一個人的api key都是不同的,這裏須要對它進行保密,不要告訴別人,不然別人能夠經過你的api key對提交的庫進行調整。獲得API key以後就須要在咱們的項目中對它進行設置保存了。git
此處有兩種方式進行配置,值分別是你在bintray上的api key和你的user name。github
BINTRAY_USER=xxx
BINTRAY_KEY=xxx複製代碼
local.properties
(若是沒有就新建它),這是本地的配置文件,通常咱們提交到github的時候,這個文件都會被ignore,因此咱們不用擔憂信息被別人看到。而後一樣加上如上配置。在最外面的那個build.gradle
文件中入以下配置web
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
// Remove it if you won't to publish SNAPSHOT version. classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.0.0"複製代碼
最新版本信息能夠在如下連接查看。apache
在library中添加binary.gradle
文件,加入以下代碼app
group = PROJ_GROUP
version = PROJ_VERSION
project.archivesBaseName = PROJ_ARTIFACTID
apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.github.dcendents.android-maven'
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += configurations.compile
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
javadoc {
options{
encoding "UTF-8"
charSet 'UTF-8'
author true
version true
links "https://androiddoc.qiniudn.com/reference/"
title "$PROJ_NAME $PROJ_VERSION"
}
}
artifacts {
archives sourcesJar
archives javadocJar
}
install {
repositories.mavenInstaller {
pom.project {
name PROJ_NAME
description PROJ_DESCRIPTION
url PROJ_WEBSITEURL
inceptionYear '2016'
packaging 'aar'
groupId PROJ_GROUP
artifactId PROJ_ARTIFACTID
version PROJ_VERSION
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
scm {
connection PROJ_VCSURL
url PROJ_WEBSITEURL
}
developers {
developer {
id DEVELOPER_ID
name DEVELOPER_NAME
email DEVELOPER_EMAIL
}
}
}
}
}
bintray {
user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : project.property('BINTRAY_USER')
key = project.hasProperty('bintrayKey') ? project.property('bintrayKey') : project.property('BINTRAY_KEY')
configurations = ['archives']
dryRun = false
publish = true
pkg {
repo = 'maven' //倉庫名
name = PROJ_NAME
licenses = ['Apache-2.0']
vcsUrl = PROJ_VCSURL
websiteUrl = PROJ_WEBSITEURL
issueTrackerUrl = PROJ_ISSUETRACKERURL
publicDownloadNumbers = true
version {
name = PROJ_VERSION
desc = PROJ_DESCRIPTION
vcsTag = PROJ_VERSION
gpg {
sign = true
}
}
}
}
//如下內容用於發佈SNAPSHOT版本,若是不須要能夠移除。
//參考自:https://www.jfrog.com/confluence/display/RTF/Gradle+Artifactory+Plugin
apply plugin: "com.jfrog.artifactory"
artifactory {
contextUrl = 'http://oss.jfrog.org/artifactory' //The base Artifactory URL if not overridden by the publisher/resolver
resolve {
repository {
repoKey = 'libs-release'
}
}
publish {
repository {
repoKey = 'oss-snapshot-local' //The Artifactory repository key to publish to
username = bintray.user
password = bintray.key
maven = true
}
defaults {
//這裏的名字和前面bintray.configurations的值一致便可,會將其包含的輸出上傳到jfrog上去
publishConfigs('archives')
}
}
}複製代碼
在library的bulid.gradle
下添加maven
apply from: './bintray.gradle'複製代碼
gradle.properties
文件添加以下配置PROJ_GROUP=com.iceuncle(項目組名)
PROJ_VERSION=1.1.1(版本號)
PROJ_NAME=PasswordBox(項目名)
PROJ_WEBSITEURL=https://github.com/iceuncle/PasswordBox(項目地址)
PROJ_ISSUETRACKERURL=(無論它)
PROJ_VCSURL=https://github.com/iceuncle/PasswordBox.git(項目倉庫)
PROJ_DESCRIPTION=android passwordbox widget(項目描述)
PROJ_ARTIFACTID=passwordbox(項目標籤)
DEVELOPER_ID=xxxxxx
DEVELOPER_NAME=xxxxxx
DEVELOPER_EMAIL=tianyang.wu998@gmail.com複製代碼
上面的例子最終在Android Studio中的引用形式爲
dependencies {
compile 'com.iceuncle:passwordbox:1.1.1'
}複製代碼
能夠發現,它的格式是 PROJ_GROUP:PROJ_ARTIFACTID:PROJ_VERSION
組成。
執行./gradlew install
若是你成功了,則能夠在module的build/outputs下面看到你的aar文件
執行 ./gradlew bintrayUpload
將庫發佈到 bintray.com
執行 ./gradlew artifactoryPublish
能夠發佈版本到 oss.jfrog.org
最後一步,須要登陸bintray.com,將咱們剛剛發佈的庫申請加入到jcenter,這樣別人才能直接引用到。
進入bintray.com/bintray/jce…,點擊Include My Package,而後在彈出的對話框中搜索並勾上你的項目。而後你能夠寫一下你的提交請求(貌似也能夠不寫?),點「Send」,接下來就看管理員審覈了。
1. HTTP/1.1 404 Not Found [message:Repo 'maven' was not found]
須要登陸bintray並建立一個maven repo
binary.gradle
文件中的repo2. 提示HTTP/1.1 401 Unauthorized [message:This resource requires authentication]
用戶名或密碼確定填錯了
3. java.net.SocketException: Operation timed out (Read failed)
須要先執行./gradlew install
,而後再執行./gradlew bintrayUpload
進行發佈。
具體的代碼參考我github上寫的一個簡單的項目:PasswordBox以爲有用的話,請多多Star噢( ̄▽ ̄)~*