上傳library到j(luò)center
-
注冊(cè)jcenter賬號(hào)并創(chuàng)建倉庫和包.
注冊(cè)選個(gè)人使用
倉庫對(duì)應(yīng)maven地址,在倉庫頁面右上角可以直接復(fù)制 maven {url $倉庫地址}
package對(duì)應(yīng)每個(gè)依賴包的存放地址脐供。即每個(gè)遠(yuǎn)程依賴的url
-
項(xiàng)目中進(jìn)行配置井辆,java library和Android library
-
在project/build.gradle下配置
dependencies{ ... // 將項(xiàng)目發(fā)布到JCenter 所需要的jar 添加依賴 classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' }
-
在module/build.gradle下配置, 注意下邊必填的
// Android library要添加的插件 apply plugin: 'com.github.dcendents.android-maven' // 應(yīng)用插件 apply plugin: 'com.jfrog.bintray' apply plugin: 'maven-publish' def baseUrl = 'https://xxx' // 可空 // 一般為項(xiàng)目開源地址 def siteUrl = baseUrl def gitUrl = "${baseUrl}/shugo" //可空 def issueUrl = "${baseUrl}/issues" // 可空 install { repositories { mavenInstaller { // This generates POM.xml with proper paramters pom.project { //添加項(xiàng)目描述 name 'Gradle Plugin for Android' url siteUrl //設(shè)置開源證書信息 licenses { license { name 'The Apache Software License, Version 2.0' url 'http://www.apache.org/licenses/LICENSE-2.0.txt' } } //添加開發(fā)者信息 developers { developer { name 'sparky' email 'douyingnan@gmail.com' } } scm { connection gitUrl developerConnection gitUrl url siteUrl } } } } } //配置上傳Bintray相關(guān)信息 bintray { user = "your user name" // * 必填 key = "your api key" // * 必填 https://bintray.com/profile/edit 中API Key configurations = ['archives'] pkg { repo = 'shugo' // * 上傳到中央倉庫的名稱,就是你創(chuàng)建的倉庫的名稱 name = 'shugo-plugin' // 上傳到j(luò)center 的項(xiàng)目名稱,就是你創(chuàng)建的package的名字 desc = 'shugo plugin' // 項(xiàng)目描述 websiteUrl = siteUrl issueTrackerUrl = issueUrl vcsUrl = gitUrl labels = ['gradle', 'plugin'] licenses = ['Apache-2.0'] publish = true } }
執(zhí)行g(shù)radlew install && gradlew bintrayUpload描孟,也可以sync之后驶睦,在右側(cè)邊欄gradle 菜單中找到module/other/install和module/publish/bintrayUpload執(zhí)行
項(xiàng)目中調(diào)用
project build.gradle :
-
allprojects {
repositories {
jcenter()
google()
mavenCentral()
maven {
url 'https://dl.bintray.com/sparky/common'
}
}
}
module build.gralde :
implementation 'xxx'
問題:
1. http 1.0 code=409
version設(shè)置的問題,升高version
2. Could not find method install() for arguments [build_e1nl4kouz9zx1zz91yxnbsvqn$_run_closure2@444f28b4] on project ':shugo-aspect' of type org.gradle.api.Project.
要上傳Android library庫需要配置android-maven和bintray.請(qǐng)確保android-maven配置正確
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' // 不同版本的plugin name和dependecence path略有不同匿醒,請(qǐng)到github查看用法
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
3. java.lang.NoSuchMethodError: Lcom/dou/shugo/shugo_aspect/SHugoAspect;.aspectOf
aop項(xiàng)目本地依賴正常運(yùn)行场航,做成依賴之后,運(yùn)行報(bào)錯(cuò)
原因未知 搞了一天沒有得到任何結(jié)果蠢廉羔。如果不能做成遠(yuǎn)程依賴就不好用了 ctm
解決: 還是早上工作腦袋清醒溉痢,找到了問題。主要是配置shugo-aspect項(xiàng)目配置aop的時(shí)候蜜另,有一句代碼是設(shè)置release項(xiàng)目不再添加aop配置直接return适室,因?yàn)楫?dāng)時(shí)是copy過來的配置,沒看仔細(xì)举瑰,啊啊啊
// 把下邊這句代碼在library中注釋掉即可捣辆,app module中可保存
/*if (!variant.buildType.isDebuggable()) {
log.debug("Skipping non-debuggable build type '${variant.buildType.name}'.")
return;
}*/
4. Error:(27, 20) Failed to resolve: com.dou.shugo:shugo-annotation:1.0.26
因?yàn)槲覀兊捻?xiàng)目只是上傳到了jcenter自己建的倉庫里,并沒有放在中央倉庫中此迅,所以如果你在項(xiàng)目中用到類似
implementation 'com.dou.shugo:shugo-annotation:1.0.26'這樣的話需要在該build.gradle文件中加reposities或者在project/build.gradle中添加
allprojects{
repositories {
...
maven {
url '對(duì)應(yīng)的你的jcenter倉庫地址'
}
}
}