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

推荐订阅源

Last Week in AI
Last Week in AI
U
Unit 42
博客园 - 【当耐特】
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Microsoft Security Blog
Microsoft Security Blog
Recent Announcements
Recent Announcements
P
Proofpoint News Feed
Martin Fowler
Martin Fowler
量子位
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
有赞技术团队
有赞技术团队
aimingoo的专栏
aimingoo的专栏
博客园 - 司徒正美
美团技术团队
雷峰网
雷峰网
小众软件
小众软件
G
Google Developers Blog
GbyAI
GbyAI
Jina AI
Jina AI
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
F
Fortinet All Blogs
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} 完成==========================================")
    }
}