android gradle plugin 7.0后maven插件更新到maven-publish,需要一些修改
發(fā)布任務(wù)
//module.gradle
plugins {
id 'maven-publish'
}
....
afterEvaluate {
publishing {
publications {
//定義一個(gè)叫myPublication的發(fā)布,名字可修改
myPublication(MavenPublication) {
//該發(fā)布依賴(lài)于release任務(wù),多渠道為xxRelease的形式
from components.release
groupId = 'com.xx.xxx'
artifactId = 'xxx'
version = '1.0'
}
//可以添加多個(gè)不同名字的發(fā)布任務(wù)
}
//需要發(fā)布的目標(biāo)倉(cāng)庫(kù)
repositories {
maven {
//倉(cāng)庫(kù)別名,方便自己識(shí)別
name = 'aliyun'
if (version.endsWith('SNAPSHOT')) {
url = '倉(cāng)庫(kù)地址'
} else {
url = 倉(cāng)庫(kù)地址'
}
//如果需要密碼認(rèn)證添加
credentials {
username = "xxx"
password = "xxxx"
}
}
}
}
}
為發(fā)布的依賴(lài)添加源碼和文檔
android{
...
//配置所有變體都添加源碼文檔
publishing {
//release和第一步中 from components.release相同
//都表示buildtype,如果有多渠道或者debug,做相應(yīng)修改
singleVariant("release") {
withSourcesJar()
withJavadocJar()
}
}
}
發(fā)布
會(huì)根據(jù)上面配置的名字,生成相對(duì)應(yīng)的命令publish[xx]PublicationTo[xxx]Repository,執(zhí)行即可。

image.png
相關(guān)資料
https://developer.android.com/studio/publish-library/upload-library#groovy
https://developer.android.com/studio/releases/gradle-plugin#publish-sources-jar
https://docs.gradle.org/current/userguide/publishing_setup.html