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

相关推荐
Larry_Yanan5 分钟前
Qt安卓开发(一)Qt6.10环境配置
android·开发语言·c++·qt·学习·ui
冬奇Lab7 分钟前
稳定性性能系列之十——卡顿问题分析:从掉帧到流畅体验
android·性能优化
stevenzqzq16 分钟前
android启动初始化和注入理解2
android
DOUBLEDdinosaur24 分钟前
屏幕数字监控 + 警报
android
M00668828 分钟前
低代码平台使用留存的技术基础与系统设计逻辑
android·rxjava
nono牛44 分钟前
深入理解gatekeeperd 与 android.hardware.gatekeeper@1.0-service调用规则
android
计算机毕设指导61 小时前
基于微信小程序的精致护肤购物系统【源码文末联系】
java·spring boot·微信小程序·小程序·tomcat·maven·intellij-idea
lxysbly1 小时前
红白机模拟器安卓版带金手指
android
·云扬·1 小时前
【实操教程】Excel文件转CSV并导入MySQL的完整步骤
android·mysql·excel
触想工业平板电脑一体机1 小时前
【触想智能】工业触控一体机在船舶海运设备上应用的特点和具体场景分析
android·网络·计算机外设·电脑·智能电视