feat: 自动化发布到Maven

This commit is contained in:
yangxisong 2025-12-11 16:25:47 +08:00
parent 6ac399cded
commit 0c831ffa6a
6 changed files with 105 additions and 60 deletions

View File

@ -1,24 +1,38 @@
Room 数据持久化Worker管理上传任务初次上传+重试共5次重试间隔10s线性增加多上传任务顺序处理
网络请求 Retrofit
### aar位置
根目录 /aar/xxx/trackingPoint-xxx-x.x.x.aar
### debug release 区别
| BuildType | 域名 | 是否打印日志 |
|----------|------|--------------|
| debug | http://192.168.2.7:18828 | 是 |
| release | https://track.23544.com | 否 |
### 使用
```groovy
/**
* 因为是本地引入AAR 所以需要手动导入下列必备依赖 版本可根据项目调整
*/
implementation("com.squareup.retrofit2:retrofit:3.0.0")
implementation("com.squareup.retrofit2:converter-moshi:3.0.0")
implementation("com.squareup.okhttp3:logging-interceptor:5.3.2")
implementation("com.squareup.moshi:moshi:1.15.2")
implementation("androidx.work:work-runtime-ktx:2.11.0")
implementation("androidx.room:room-runtime:2.8.4")
implementation("androidx.room:room-ktx:2.8.4")
#### 1.0.4
```kotlin
repositories {
google()
mavenCentral()
maven {
url = uri("http://192.168.2.14:8081/repository/maven-releases/")
isAllowInsecureProtocol = true
credentials {
username = "admin"
password = "qwer1234.."
}
}
maven {
url = uri("http://192.168.2.14:8081/repository/maven-snapshots/")
isAllowInsecureProtocol = true
credentials {
username = "admin"
password = "qwer1234.."
}
}
}
//测试环境
debugImplementation("com.yuanxuan:tracking_point:x.x.x-SNAPSHOT")
//生产环境
releaseImplementation("com.yuanxuan:tracking_point:x.x.x")
```
```kotlin
/**

View File

@ -20,4 +20,10 @@ kotlin.code.style=official
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.nonTransitiveRClass=true
mavenReleaseRepoUrl=http://192.168.2.14:8081/repository/maven-releases/
mavenDebugRepoUrl=http://192.168.2.14:8081/repository/maven-snapshots/
mavenUsername=admin
mavenPassword=qwer1234..
baseReleaseUrl=https://track.23544.com
baseDebugUrl=http://192.168.2.7:18828

View File

@ -39,6 +39,4 @@ androidx-room-ktx = { group = "androidx.room", name = "room-ktx", version.ref =
android-application = { id = "com.android.application", version.ref = "agp" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
android-library = { id = "com.android.library", version.ref = "agp" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
maven-publish = { id = "maven-publish" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }

View File

@ -1,12 +1,21 @@
import org.gradle.api.tasks.Delete
import org.gradle.api.publish.maven.MavenPublication
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.ksp)
id("maven-publish")
}
group = "com.yuanxuan"
version = "1.0.5"
version = "1.0.1"
val baseReleaseUrl: Provider<String> = providers.gradleProperty("baseReleaseUrl")
val baseDebugUrl: Provider<String> = providers.gradleProperty("baseDebugUrl")
val mavenReleaseRepoUrl: Provider<String> = providers.gradleProperty("mavenReleaseRepoUrl")
val mavenDebugRepoUrl: Provider<String> = providers.gradleProperty("mavenDebugRepoUrl")
val mavenUsername: Provider<String> = providers.gradleProperty("mavenUsername")
val mavenPassword: Provider<String> = providers.gradleProperty("mavenPassword")
android {
namespace = "com.yuanxuan.tracking_point.library"
@ -21,10 +30,10 @@ android {
buildTypes {
debug {
buildConfigField("String", "BASE_URL", "\"http://192.168.2.7:18828\"")
buildConfigField("String", "BASE_URL", "\"${baseDebugUrl.get()}\"")
}
release {
buildConfigField("String", "BASE_URL", "\"https://track.23544.com\"")
buildConfigField("String", "BASE_URL", "\"${baseReleaseUrl.get()}\"")
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
@ -37,10 +46,14 @@ android {
targetCompatibility = JavaVersion.VERSION_11
}
buildFeatures {
buildConfig = true
}
publishing {
singleVariant("debug")
singleVariant("release")
}
}
kotlin {
@ -51,6 +64,50 @@ ksp {
arg("room.schemaLocation", "$projectDir/schemas")
}
afterEvaluate {
publishing {
publications {
register<MavenPublication>("debug") {
groupId = project.group.toString()
artifactId = "tracking_point"
version = "${project.version}-SNAPSHOT"
from(components["debug"])
}
register<MavenPublication>("release") {
groupId = project.group.toString()
artifactId = "tracking_point"
version = "${project.version}"
from(components["release"])
}
}
repositories {
maven {
name = "debugRepo"
url = uri(mavenDebugRepoUrl.get())
isAllowInsecureProtocol = true
credentials {
username = mavenUsername.get()
password = mavenPassword.get()
}
}
maven {
name = "releaseRepo"
url = uri(mavenReleaseRepoUrl.get())
isAllowInsecureProtocol = true
credentials {
username = mavenUsername.get()
password = mavenPassword.get()
}
}
}
}
}
dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.work.ktx)
@ -64,42 +121,12 @@ dependencies {
ksp(libs.androidx.room.ksp)
}
// Task to clean the 'aar' directory
tasks.register<Delete>("cleanAar") {
group = "build"
description = "Deletes the root 'aar' directory to ensure a clean build."
delete(rootProject.file("aar"))
}
tasks.register("buildAar") {
group = "build"
description = "Cleans, builds, and copies release and debug AARs."
dependsOn("cleanAar", "assembleDebug", "assembleRelease")
doLast {
val releaseDestDir = rootProject.file("aar/release")
val debugDestDir = rootProject.file("aar/debug")
val aarVersion = project.version
copy {
from(layout.buildDirectory.file("outputs/aar/library-release.aar"))
into(releaseDestDir)
rename { "trackingPoint-release-$aarVersion.aar" }
}
copy {
from(layout.buildDirectory.file("outputs/aar/library-debug.aar"))
into(debugDestDir)
rename { "trackingPoint-debug-$aarVersion.aar" }
}
println(
"""
AARs have been built and copied:
- Release: ${releaseDestDir.absolutePath}/trackingPoint-release-$aarVersion.aar
- Debug: ${debugDestDir.absolutePath}/trackingPoint-debug-$aarVersion.aar
""".trimIndent()
)
}
tasks.register("publishAll") {
group = "publishing"
description = "Publish both Debug and Release artifacts to their repositories."
dependsOn(
"publishDebugPublicationToDebugRepoRepository",
"publishReleasePublicationToReleaseRepoRepository"
)
}