build gradle 7.x 上传moudle打包的aar到远程仓库,能同时把本地的引用的一个aar一起发布上传吗
是的,你可以使用Gradle来上传一个moudle打包的aar到远程仓库,并同时发布上传本地引用的aar。以下是一个示例的Gradle配置:
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.x'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
}
}
apply plugin: 'maven'
apply plugin: 'com.github.dcendents.android-maven'
group = 'com.example'
version = '1.0.0'
uploadArchives {
repositories {
mavenDeployer {
repository(url: 'http://your_remote_repository') {
authentication(userName: 'your_username', password: 'your_password')
}
pom.project {
name 'Your Library Name'
packaging 'aar'
description 'Your library description'
url 'http://your_library_url'
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id 'your_developer_id'
name 'Your Name'
}
}
}
}
}
}
apply plugin: 'com.android.library'
android {
// 配置Android构建信息
}
dependencies {
// 配置本地引用的aar路径
implementation files('libs/local_aar_library.aar')
// 配置其他依赖关系
}
task packageAar(type: Copy) {
from('build/outputs/aar')
into('libs')
include('*.aar')
}
// 定义上传aar任务依赖于打包aar任务
uploadArchives.dependsOn packageAar
./gradlew uploadArchives
这样就可以将moudle打包的aar和本地引用的aar一起上传到远程仓库中了。请根据实际情况修改配置中的URL、用户名、密码、开发人员信息等。
uploadArchives 这是6.x的用法 7.x用的publishing
对不起,我之前提供的是旧版本的Gradle用法。确实,在Gradle 7.x版本中,uploadArchives
任务已被废弃,应使用publishing
插件来上传aar到远程仓库。以下是在Gradle 7.x版本中使用publishing
插件的示例配置:
plugins {
id 'maven-publish'
}
publishing {
publications {
mavenAar(MavenPublication) {
groupId = 'com.example'
artifactId = 'your_library_name'
version = '1.0.0'
// 配置aar文件
artifact("$buildDir/outputs/aar/your_library_name-release.aar")
// 配置pom文件
pom {
name 'Your Library Name'
description 'Your library description'
url 'http://your_library_url'
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id 'your_developer_id'
name 'Your Name'
}
}
}
}
}
repositories {
maven {
url 'http://your_remote_repository'
credentials {
username = 'your_username'
password = 'your_password'
}
}
}
}
apply plugin: 'com.android.library'
android {
// 配置Android构建信息
}
dependencies {
// 配置本地引用的aar路径
implementation files('libs/local_aar_library.aar')
// 配置其他依赖关系
}
task packageAar(type: Copy) {
from('build/outputs/aar')
into('libs')
include('*.aar')
}
// 定义发布aar任务依赖于打包aar任务
publish.dependsOn packageAar
./gradlew publish
这样就可以将moudle打包的aar和本地引用的aar一起发布上传到远程仓库中了。请根据实际情况修改配置中的URL、用户名、密码、开发人员信息等。
本地引用的aar 一起上传后怎么引用呢
一旦将本地引用的aar一起上传到远程仓库,你可以通过在项目的build.gradle文件中添加相应的依赖来引用它。
allprojects {
repositories {
google()
mavenCentral()
maven {
url 'http://your_remote_repository'
credentials {
username = 'your_username'
password = 'your_password'
}
}
}
}
dependencies {
implementation 'com.example:your_library_name:1.0.0'
// 其他依赖关系
}
请确保在添加依赖时使用正确的groupId
、artifactId
和version
来匹配上传的aar的信息。
然后,重新同步项目,Gradle会从远程仓库下载并引用上传的aar文件。这样,你就可以在项目中使用上传的aar库了。
如果你在本地开发时不想使用远程仓库的aar,可以将本地引用的aar修改为远程引用,如:
dependencies {
implementation 'com.example:your_local_aar_library:1.0.0'
// 其他依赖关系
}
然后,在发布版本时再切换回远程仓库的引用。
记得在使用远程仓库的用户名和密码时,确保保密性和安全性,不要将敏感信息直接暴露在脚本中。
上传本地饮用的aar到远程仓库怎么在添加依赖时使用正确的groupId、artifactId和version来匹配上传的aar的信息
当你上传本地引用的aar到远程仓库时,你需要确保在添加依赖时使用正确的groupId
、artifactId
和version
来匹配上传的aar的信息。以下是一些步骤来确保匹配正确的信息:
group
、archivesBaseName
和version
属性。例如:group = 'com.example'
archivesBaseName = 'your_local_aar_library'
version = '1.0.0'
groupId
、artifactId
和version
属性。例如:group = 'com.example'
version = '1.0.0'
groupId
、artifactId
和version
属性来配置MavenPublication的信息。例如:publishing {
publications {
mavenAar(MavenPublication) {
groupId = 'com.example'
artifactId = 'your_local_aar_library'
version = '1.0.0'
// 其他配置
}
}
// 其他配置
}
groupId
、artifactId
和version
来添加依赖。例如:dependencies {
implementation 'com.example:your_local_aar_library:1.0.0'
// 其他依赖关系
}
确保在这些步骤中使用相同的groupId
、artifactId
和version
来匹配上传的aar的信息,这样就能正确引用上传到远程仓库的aar了。