使用Gradle發(fā)布aar項目到Jcenter倉庫

jcenter兼容maven gradle lvy等形式 方便我們項目的開源工作

注冊賬號

https://bintray.com/這邊有一個要特別注意的點(diǎn),注冊的時候點(diǎn)opensource那個?。〔蝗皇瞧髽I(yè)相關(guān)的,沒有辦法建立自己的代碼倉,當(dāng)時被這個坑了很久。注冊的賬號一般國內(nèi)的qq郵箱什么的不能使用,建議使用gmail

獲取你的API Key

image

編輯你當(dāng)前l(fā)ibrary文件的build.gradle

1.根節(jié)點(diǎn)添加插件

apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

2.根節(jié)點(diǎn)添加版本號

version = "0.1" //修改后重新上傳的標(biāo)識號

3.若使用非GBK格式編碼,添加格式兼容

allprojects {
    repositories {
        google()
        jcenter()
        mavenLocal()
        maven {
            url "${project.rootDir}/../../libraries/m2repository"
        }
        flatDir {
            dirs 'libs'
        }
    }
    
    //此處添加的UTF-8格式
    tasks.withType(Javadoc) {
        options.addStringOption('Xdoclint:none', '-quiet')
        options.addStringOption('encoding', 'UTF-8')
    }
}

4.根節(jié)點(diǎn)加aar&&jcenter相關(guān)

def siteUrl = '' //此處為github項目地址
def gitUrl = ''//此處為git地址 ******.git
group = "" //唯一區(qū)別碼 一般可以使用packageId 

install {
    repositories.mavenInstaller {
        // This generates POM.xml with proper parameters
        pom {
            project {
                packaging 'aar'
                name '' //項目名稱
                url siteUrl
                licenses {
                    license {
                        name 'The Apache Software License, Version 2.0'
                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    }
                }
                developers {
                    developer {
                        id '' //jcenter id
                        name '' //jcenter name
                        email '' //jcenter mail
                    }
                }
                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
}

artifacts {
    archives javadocJar
    archives sourcesJar
}

//local.properties 內(nèi)添加 bintray.user bintray.apikey
Properties properties = new Properties()
boolean isHasFile = false
if (project.rootProject.file('local.properties') != null){
    isHasFile = true
    properties.load(project.rootProject.file('local.properties').newDataInputStream())
}
bintray {
    user = isHasFile ? properties.getProperty("bintray.user") : System.getenv("bintray.user")
    key = isHasFile ? properties.getProperty("bintray.apikey") : System.getenv("bintray.apikey")
    configurations = ['archives']
    pkg {
        repo = "" //jcenter倉庫名 此處注意要現(xiàn)在jcenter創(chuàng)建這個名稱的repo 不然上傳報錯
        name = "" //jcenter 項目名
        websiteUrl = siteUrl
        vcsUrl = gitUrl
        licenses = ["Apache-2.0"]
        publish = true
    }
}

5.執(zhí)行上傳

./gradew javadocJar
./gradew sourcesJar
./gradew install
./gradew bintrayUpload
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容