Skip to content

Instantly share code, notes, and snippets.

@rayworks
Last active June 26, 2024 02:44
Show Gist options
  • Save rayworks/e1dbe5176df7d60b184f839d48a7bfd7 to your computer and use it in GitHub Desktop.
Save rayworks/e1dbe5176df7d60b184f839d48a7bfd7 to your computer and use it in GitHub Desktop.
The script to deploy Android aar files to maven repository
apply plugin: 'maven-publish'
// https://developer.android.google.cn/studio/build/maven-publish-plugin
// Because the components are created only during the afterEvaluate phase, you must
// configure your publications using the afterEvaluate() lifecycle method.
afterEvaluate {
publishing {
publications {
AgoraPub(MavenPublication) {
groupId = GROUP_ID
artifactId = ARTIFACT_ID
version = VERSION
// https://stackoverflow.com/questions/55864101/no-longer-able-to-use-bundlereleaseaar-in-mavenpublication
artifact bundleReleaseAar
//artifact sourcesJar
//artifact packageJavadoc
pom.withXml {
def dependenciesNode = asNode().appendNode("dependencies")
configurations.implementation.allDependencies.forEach() {
Dependency dependency ->
if (dependency.version != "unspecified" && dependency.name != "unspecified") {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', dependency.group)
dependencyNode.appendNode('artifactId', dependency.name)
dependencyNode.appendNode('version', dependency.version)
} else {
println(">>> [WARN] Excluded module: " + dependency.group + ":" + dependency.name)
}
}
}
}
}
repositories {
maven {
url = VERSION.contains("SNAPSHOT") ? MAVEN_REPO_SNAPSHOT_URL : MAVEN_REPO_RELEASE_URL
println(">>> MAVEN_REPO : " + url)
credentials {
username USERNAME
password PASSWORD
}
if (PASSWORD != null) {
println("USERNAME: " + USERNAME + ", PASSWORD: " + PASSWORD.substring(0, 1) + "***")
}
}
}
}
}
@rayworks
Copy link
Author

rayworks commented Jun 2, 2021

exec ./gradlew publishToMavenLocal to deploy library to local repo

exec ./gradlew publish to deploy library to remote repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment