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

推荐订阅源

D
DataBreaches.Net
小众软件
小众软件
腾讯CDC
Jina AI
Jina AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Cloudflare Blog
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
Y
Y Combinator Blog
Engineering at Meta
Engineering at Meta
美团技术团队
U
Unit 42
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
WordPress大学
WordPress大学
N
Netflix TechBlog - Medium
Microsoft Security Blog
Microsoft Security Blog
L
LangChain Blog
罗磊的独立博客
aimingoo的专栏
aimingoo的专栏
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
G
Google Developers Blog
C
Check Point Blog
大猫的无限游戏
大猫的无限游戏
Recent Announcements
Recent Announcements

博客园 - 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} 完成==========================================")
    }
}