
官网的代码,不解释环境
Gradle版本:6.5
AGP 版本 :4.1.2
Android Studio Arctic Fox | 2020.3.1 Patch 2
Gradle脚本语言:Groovy
//groovy
apply plugin: 'maven'
android {
...
}
uploadArchives {
repositories {
mavenDeployer {
repository(url: 'https://packages.aliyun.com/maven/repository/') {
authentication(
userName: 'xxxxxxxxxxxxx',
password: 'e[xxxxxxxxxxxxx'
)
}
snapshotRepository(url: 'https://packages.aliyun.com/maven/repository/') {
authentication(
userName: 'xxxxxxxxxxxxx',
password: 'e[xxxxxxxxxxxxx'
)
}
pom.version = android.defaultConfig.versionName
pom.artifactId = 'final'
pom.groupId = 'com.example'
}
}
}
执行 uploadArchives,发布到阿里云效
//mac ./gradlew :moduleName:uploadArchives //windows gradlew :moduleName:uploadArchives2. 使用 maven-publish插件上传aar
编写上传Task环境
Gradle版本:7.0.2
AGP 版本 :7.0.2
Android Studio Arctic Fox | 2020.3.1 Patch 2
Gradle脚本语言:kotlin
//kotlin
plugins {
//maven插件在6.8之后移除了
//使用新的maven-publish插件
//添加maven-publish插件
id("maven-publish")
}
android {
...
}
afterevaluate {
publishing {
publications {
//随便取,这是task的名字
//可以create多个
//比如 release 一个 debug一个,配置不同的信息
create("snapshot") {
//release 或者debug
from(components.getByName("release"))
//不解释
groupId = "com.example.MyLibrary"
//不解释
artifactId = "final"
//不解释
version = "1.0"
repositories {
maven {
//repository的名字,随便取
name = "myRepo"
//阿里云效的地址,仓库地址
url = uri("https://packages.aliyun.com/maven/repository/")
credentials {
//阿里云效的用户名
username = "xxxxxxxx"
//阿里云效的密码
password = "e[xxxxxxxx"
}
}
}
}
}
}
}
执行 publish,发布到阿里云效
//mac ./gradlew :moduleName:publish //windows gradlew :moduleName:publish