惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
博客园 - 司徒正美
小众软件
小众软件
H
Help Net Security
博客园 - 聂微东
宝玉的分享
宝玉的分享
Jina AI
Jina AI
酷 壳 – CoolShell
酷 壳 – CoolShell
阮一峰的网络日志
阮一峰的网络日志
M
MIT News - Artificial intelligence
博客园 - 【当耐特】
U
Unit 42
大猫的无限游戏
大猫的无限游戏
Apple Machine Learning Research
Apple Machine Learning Research
S
SegmentFault 最新的问题
腾讯CDC
MongoDB | Blog
MongoDB | Blog
云风的 BLOG
云风的 BLOG
J
Java Code Geeks
I
InfoQ
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Martin Fowler
Martin Fowler
博客园 - 三生石上(FineUI控件)
Vercel News
Vercel News

博客园 - hangox

Claude Code 自定义状态栏配置指南 如何给 Claude 中的网页做截图 idea 插件兼容 K2 模式 IDEA 不提示 gitlab-ci 字段问题 不要随便使用 npm 源加速站点 Xcode Format Swift 代码 idea Convert File To Kotlin File 多 Commit 问题 ApkList 源问题修复 BCM94360CS2 黑苹果 macOS Sonoma Wifi 不能开启修复 NginxProxyManager 数据库迁移记录 android ConcurrentModificationException 错误 Android Studio 插件分享——Gradle Utilities Android Studio 插件分享——Jadx Class Decompiler templete Android Studio 3.0 新特性 Android SpringAnimator初探 关于Android菜单上的记录 升级到 classpath 'com.android.tools.build:gradle:1.0.0-rc1 OnScrollListenerPro
AGP 8.0+ Publish
hangox · 2025-06-23 · via 博客园 - hangox

分享一个脚本

apply plugin: 'maven-publish'
def projectPath = project.projectDir.toString()
def divPath = projectPath.replace(rootProject.projectDir.toString(), "").replace(File.separator, ".").replaceFirst("\\.", "")
def lastDotIndex = divPath.lastIndexOf(".")
def groupIdStart = "com.hangox.android"
if (lastDotIndex != -1) {
    def packageName = divPath.substring(0, lastDotIndex)
    group = "${groupIdStart}.${packageName}"
} else {
    group = groupIdStart
}
def artifactIdName = project.name
// 增加时间戳,避免版本冲突

def bigVersion = "1.0.0"
def timestamp = new Date().format("yyyyMMddHHmmss")
version = "$bigVersion-${timestamp}"


tasks.register("sourcesJar", Jar) {
    archiveClassifier = 'sources'
    from android.sourceSets.main.java.srcDirs
}
android {
    publishing {
        singleVariant("release")
        singleVariant("debug")
    }
}
afterEvaluate {
    publishing {
        publications {
            release(MavenPublication) {
                from components.release
                artifact sourcesJar
                artifactId = artifactIdName
            }
            debug(MavenPublication) {
                from components.debug
                artifact sourcesJar
                artifactId = artifactIdName
            }
        }

        repositories {
            maven {
                name "ProjectLocal"
                def repos = new File(rootProject.buildDir, "repos")
                url repos.absolutePath
            }
            def customReposLocation = rootProject.getProperties()["custom.repos.path"]
            if (customReposLocation) {
                maven {
                    name "CustomRepos"
                    def repos = new File(customReposLocation)
                    url repos.absolutePath
                }
            }

        
        }

    }
}

// 在所有 PublishToMavenRepository 类型的任务中加入 doLast 回调,在任务结束后打印发布的信息
tasks.withType(PublishToMavenRepository).configureEach {
    doLast {
        def repositoryName = it.repository.name
        def displayName = "${project.group}:${artifactIdName}"
        project.logger.lifecycle("=================================发布 ${displayName} 完成==========================================")
        project.logger.lifecycle("发布到的 maven 仓库(${repositoryName}) 信息为: ${project.group}:${artifactIdName}:${project.version}")
        project.logger.lifecycle("=================================发布 ${displayName} 完成==========================================")
    }
}