android studio 使用maven-publish 插件上传aar到远程maven仓库

上传插件编写

1、在工程目录下添加upload.gradle文件

kotlin 复制代码
apply plugin: 'maven-publish'


def RELEASE_REPOSITORY_URL = 'http://xxx.xx.com/artifactory/repository/release/'
def SNAPSHOT_REPOSITORY_URL =  'http://xxx.xx.com/artifactory/repository/snapshot/'

def USERNAME = "developer"
def PASSWORD = "developer"

afterEvaluate {
    publishing {
        //配置maven 仓库
        repositories { RepositoryHandler handler ->
            handler.maven { MavenArtifactRepository mavenArtifactRepository ->
                allowInsecureProtocol(true)
                url = VERSION.endsWith('SNAPSHOT') ? SNAPSHOT_REPOSITORY_URL : RELEASE_REPOSITORY_URL
                credentials {
                    username USERNAME
                    password PASSWORD
                }
            }
        }

        //配置发布产物
        publications { PublicationContainer publicationContainer ->
            //发布 snapshot 包
            debug(MavenPublication) {
                from components.debug
                artifact sourceJar
                groupId = GROUP_ID
                artifactId = ARTIFACT_ID
                version  = VERSION
            }

            release(MavenPublication) {
                // Applies the component for the release build variant.
                from components.release
                artifact sourceJar
                groupId = GROUP_ID
                artifactId = ARTIFACT_ID
                version  = VERSION
            }
        }
    }
}


//增加上传源码的task
task sourceJar(type:Jar){
    from android.sourceSets.main.java.srcDirs
    archiveClassifier = "source"
}

2、在要上传的module的build.gradle添加插件

kotlin 复制代码
plugins {
    id 'com.android.library'
}

apply from: "../upload.gradle"

3、在要上传的module配置对应的aar信息,新建gradle.properties

kotlin 复制代码
GROUP_ID=com.xx.card
ARTIFACT_ID=card
VERSION=0.0.1

遇到的问题以及解决方案

1、如何区分上传SNAPSHOT和正式版本?

url = VERSION.endsWith('SNAPSHOT') 插件内通过版本字符串中是否含有该字段

2、多渠道打包如何上传对应渠道

from components.debug,把debug修改成对应渠道即可。参考Build Variant

相关推荐
2501_9400078911 分钟前
Flutter for OpenHarmony三国杀攻略App实战 - 性能优化与最佳实践
android·flutter·性能优化
Rysxt_1 小时前
UniApp获取安卓系统权限教程
android·uni-app
毕设源码-朱学姐2 小时前
【开题答辩全过程】以 基于安卓的教师上课辅助系统为例,包含答辩的问题和答案
android
诸神黄昏EX3 小时前
Android Safety 系列专题【篇二:AVB签名】
android
2601_949543013 小时前
Flutter for OpenHarmony垃圾分类指南App实战:意见反馈实现
android·flutter
无尽的沉默3 小时前
使用Spring Initializr 快速创建Maven管理的springBoot项目
spring boot·spring·maven
urkay-4 小时前
Android 中实现 HMAC-SHA256
android·开发语言·python
YIN_尹4 小时前
【MySQL】增删查改的艺术——数据库CRUD完全指南(下)
android·数据库·mysql
m0_748233174 小时前
PHP8.0新特性全解析
android
一起养小猫4 小时前
Flutter for OpenHarmony 实战:从零开发一款五子棋游戏
android·前端·javascript·flutter·游戏·harmonyos