1. 在项目根目录创建 publish.gradle
apply plugin: 'maven-publish'
Properties properties = new Properties()
def file = new File(rootProject.projectDir,'local.properties')
if (null != file && file.exists()) {
properties.load(file.newDataInputStream())
}
publishing {
repositories {
maven {
url 'http://xxxxxx/xxxxxx/xxxxxx/'
credentials {
username properties.getProperty('maven.username')
password properties.getProperty('maven.password')
}
}
}
}
2. 在local.properties配置自己Maven用户名密码
maven.username=littonishir
maven.password=xxxxxxxxxxxx
3. 在gradle.properties配置一些字段方便后续的管理。
IS_APPLICATION=false
ARTIFACTID=flavor
GROUPID=com.litton.ishir
VERSION=0.0.1.test001
4. 在需要配置上传aar的项目build.gradle中,做最后的配置。
- 引入 apply from: ‘…/publish.gradle’
- 编写afterEvaluate
- myflavor这里换成你自己libary的名字
if (IS_APPLICATION.toBoolean()) {
apply plugin: 'com.android.application'
} else {
apply plugin: 'com.android.library'
}
apply plugin: 'kotlin-android'
apply from: '../publish.gradle'
android {
compileSdk 31
defaultConfig {
if (IS_APPLICATION.toBoolean()) {
applicationId "com.litton.myflavor"
}
minSdk 23
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
...
flavorDimensions "channel", "isPay"
productFlavors {
Huawei {
dimension "channel"
}
Xiaomi {
dimension "channel"
}
Pay {
dimension "isPay"
}
Free {
dimension "isPay"
}
}
afterEvaluate {
publishing {
publications {
myflavor(MavenPublication) {
from components.HuaweiPayRelease
artifactId ARTIFACTID
groupId GROUPID
version VERSION
println("Platform is ${groupId}:${artifactId}:${version}")
}
}
}
}
}
5. 执行Task上传即可 publishXXXPublicationToMavenRepository
