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

相关推荐
CYY952 小时前
Compose 入门篇
android·kotlin
杉氧5 小时前
Compose 时代的 MVI 架构:如何用单向数据流驱动复杂 UI?
android·架构·android jetpack
杉氧5 小时前
Modifier 的艺术:为什么链式调用的顺序决定了UI 的生命周期?
android·架构·android jetpack
李斯维6 小时前
腾讯 XLog 日志框架 Android 端接入
android·android studio·android jetpack
黄林晴6 小时前
Kotlin Toolchain 0.11 发布:Amper 正式更名,统一 kotlin 命令
android·kotlin
雨白8 小时前
C语言基础快速入门与指针初探
android
Exploring9 小时前
避坑指南:升级 AGP 8.0+ 导致第三方 SDK 编译崩溃的完美解决方案
android
石山岭1 天前
自己动手写了一个 Android 虚拟定位 App:GPSSimulate 技术实
android·前端
杉氧1 天前
副作用 (Side Effects) 全攻略:如何像大师一样掌控 Composable 的生命周期?
android·架构·android jetpack
Kapaseker1 天前
Kotlin Toolchain 0.11 发布:主要是把 Amper 干没了
android·kotlin