Bintray網(wǎng)頁操作
- 一定要在下面這個網(wǎng)址注冊(個人賬戶)
https://bintray.com/signup/oss - 不要在這里注冊 https://bintray.com(這是公司組織注冊的賬戶)
- 用github或者谷歌郵箱注冊掸掸,不能使用國內(nèi)郵箱
創(chuàng)建一個組織
在該組織下創(chuàng)建倉庫
至此,組織–>倉庫 創(chuàng)建好了
獲取key和user
拿到這些信息,gradle配置會用到
代碼gradle配置
簡介
在項目根目錄下的 local.properties 中填寫我們的 user 和 API key秦躯,這里的內(nèi)容是完全可以放在 gradle.properties 中的,但是通常我們的開源庫都會發(fā)到 Github 的公共倉庫中率拒,如果這樣的話那我們的 API key 就會暴露給其他人政己,那當(dāng)然是不行的,所以我們就在 git 忽略的 local.properties 中配置我們的 API key砰左。
BINTRAY_USER=werbhelius
BINTRAY_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- 項目根gradle添加
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
2.Module的gradle配置
這里向大家介紹一下 aar 和 jar 的區(qū)別。
.jar :只包含了 class 文件與清單文件场航,不包含資源文件缠导,如圖片等所有 res 中的文件。
.aar:包含所有資源溉痢,class** 以及 res 資源文件全部包含僻造。
如果你只是一個簡單的類庫那么使用生成的 *.jar文件即可;如果你的是一個UI庫孩饼,包含一些自己寫的控件布局文件以及字體等資源文件那么就只能使用 *.aar 文件髓削。
在我們開源庫的目錄下,新建一個 bintray.gradle 文件镀娶,用于上傳開源庫以及配置發(fā)布的文件內(nèi)容包括源碼立膛,文檔以及 AAR。
apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.github.dcendents.android-maven'
//上傳到Jcenter 相關(guān)配置 以下配置都需要修改成自己的數(shù)據(jù)
def siteUrl = 'https://github.com/wang0420/LocalBroadcastManagerSample' // # 項目的主頁
def gitUrl = 'https://github.com/wang0420/LocalBroadcastManagerSample' // # Git倉庫的url
def issueUrl = 'https://github.com/wang0420/LocalBroadcastManagerSample/issues' // # Git倉庫issues的url
//參考 compile 'groupId:artifactId:version'梯码,groupId就是group version下面的版本
group "com.github.wang" //groupId
version = "1.0.0" // # 發(fā)布版本號
def artifactIdName = 'local-broadcast-compiler'// # artifactId
def projectName = 'broadcastCompiler' // #這個是顯示在bintray 倉庫中的項目名字宝泵,一般可用項目名稱
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"http:// 你要上傳的庫的名字 需要和建倉庫用的名字一致,即在組下面建立的倉庫名稱
name = projectName //這個是顯示在bintray 倉庫中的項目名字,一般可用項目名稱
websiteUrl = siteUrl
vcsUrl = gitUrl
issueTrackerUrl = issueUrl
userOrg = "wangwei15" //組織名 需要和建組織用的名字一致
//自己創(chuàng)建的organization名稱轩娶,一定要全是小寫字母儿奶,即使當(dāng)時創(chuàng)建的名稱含有大寫,這里全部轉(zhuǎn)換為小寫鳄抒,否則404
licenses = ['MIT']//不能隨便寫闯捎,只能是倉庫創(chuàng)建時選擇的license type
publish = true// 是否是公開項目椰弊,公開別人可以引用
}
}
install {
repositories.mavenInstaller {
// This generates POM.xml with proper parameters
pom {
project {
name artifactIdName //project.name的屬性值建議與project.artifactId一致
artifactId artifactIdName //依賴包最后面的部分
description 'A android lib allows you to easily use.'
url siteUrl
// Set your license
licenses {
license {
name 'MIT' //和之前自己定義的協(xié)議一致
url 'https://raw.githubusercontent.com/minggo620/Pluto-Android/master/LICENSE'
}
}
developers {
developer {
id 'wangwei' //填寫的一些基本信息
name '王偉'
email '709693972@qq.com'
}
}
scm {
connection gitUrl
developerConnection gitUrl
url siteUrl
}
}
}
}
}
if (project.getPlugins().hasPlugin('com.android.application') || project.getPlugins().hasPlugin('com.android.library')) {
println('--------android--------')
//android javadoc和sources文件的生成
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
task javadoc(type: Javadoc) {
failOnError false //必須添加以免出錯
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
}
} else {
println('--------java--------')
//java javadoc和sources文件的生成
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
}
artifacts {
archives sourcesJar
archives javadocJar
}
//在構(gòu)建生成的時候有可能會報GBK編碼等錯誤,可能需要添加UTF-8聲明瓤鼻,如下:
javadoc {
options {
//如果你的項目里面有中文注釋的話秉版,必須將格式設(shè)置為UTF-8,不然會出現(xiàn)亂碼
encoding "UTF-8"
charSet 'UTF-8'
author true
version true
links "http://docs.oracle.com/javase/7/docs/api"
}
}
3.在我們開源庫中的 build.gradle 文件中引入 bintary.gradle 娱仔,注意引入的命令需要寫在最后一行沐飘,不然會報錯。
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
apply from: './bintray.gradle'
4.當(dāng)上述的配置全部完成之后牲迫,我們可以上傳我們的開源庫了耐朴,打開 Terminal,執(zhí)行 ./gradlew install盹憎,執(zhí)行完成后筛峭,打開 build 目錄你會發(fā)現(xiàn)生成了 aar 包、javadoc 文檔陪每、sources 源碼以及上傳 maven 需要的 pom 配置文件影晓。
5.生成上述文件后,繼續(xù)在 Terminal 中執(zhí)行 ./gradlew bintrayUpload 提示成功之后檩禾,我們的開源庫就發(fā)布成功啦挂签。
發(fā)布成功之后,打開之前 bintray 網(wǎng)頁盼产,你會發(fā)現(xiàn)在之前我們創(chuàng)建的 maven 倉庫中饵婆,已經(jīng)有我們剛剛發(fā)布的庫了。
發(fā)布到 JCenter
在 bintray 開源庫的網(wǎng)頁中戏售,右邊會有 Add to JCenter 的提示侨核,點擊提交 commit 就可以啦,一般在幾個小時或一天的時間就會提示你添加成功灌灾。
問題記錄
1搓译、http://www.reibang.com/p/9c6ac57e80f4
2、第一次必須要發(fā)布審核才能使用 審核期間 可以在根目錄的build 里面依賴自己的mavan 倉庫使用
maven {
url 'https://dl.bintray.com/wangwei15/maven/'
}
上傳JCenter 步驟
1锋喜、根目錄build 添加
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
2些己、修改 local.properties 用戶名稱及key
3、我們開源庫中的 upload_bintray.gradle 文件中引入 bintary.gradle 嘿般,注意引入的命令需要寫在最后一行轴总,不然會報錯。
4博个、修改上述文件#號注釋的地方
5、執(zhí)行 gradlew install 用于將項目編譯功偿、打包生成 pom盆佣,aar 等文件往堡;
6、執(zhí)行 gradlew bintrayUpload 用于將生成的 pom共耍,aar 等文件上傳至 bintray 倉庫中虑灰;
7、如果是第一次上傳 需要發(fā)布到 JCenter 痹兜,Add to JCenter 的提示穆咐,點擊提交 commit 就可以啦