feat: 自动化发布到Maven
This commit is contained in:
parent
6ac399cded
commit
0c831ffa6a
40
Readme.md
40
Readme.md
|
|
@ -1,24 +1,38 @@
|
||||||
Room 数据持久化;Worker管理上传任务,初次上传+重试共5次,重试间隔10s线性增加;多上传任务顺序处理;
|
Room 数据持久化;Worker管理上传任务,初次上传+重试共5次,重试间隔10s线性增加;多上传任务顺序处理;
|
||||||
网络请求 Retrofit
|
网络请求 Retrofit
|
||||||
### aar位置
|
|
||||||
根目录 /aar/xxx/trackingPoint-xxx-x.x.x.aar
|
|
||||||
### debug release 区别
|
### debug release 区别
|
||||||
| BuildType | 域名 | 是否打印日志 |
|
| BuildType | 域名 | 是否打印日志 |
|
||||||
|----------|------|--------------|
|
|----------|------|--------------|
|
||||||
| debug | http://192.168.2.7:18828 | 是 |
|
| debug | http://192.168.2.7:18828 | 是 |
|
||||||
| release | https://track.23544.com | 否 |
|
| release | https://track.23544.com | 否 |
|
||||||
|
|
||||||
### 使用
|
### 使用
|
||||||
```groovy
|
#### 1.0.4
|
||||||
/**
|
```kotlin
|
||||||
* 因为是本地引入AAR 所以需要手动导入下列必备依赖 版本可根据项目调整
|
repositories {
|
||||||
*/
|
google()
|
||||||
implementation("com.squareup.retrofit2:retrofit:3.0.0")
|
mavenCentral()
|
||||||
implementation("com.squareup.retrofit2:converter-moshi:3.0.0")
|
maven {
|
||||||
implementation("com.squareup.okhttp3:logging-interceptor:5.3.2")
|
url = uri("http://192.168.2.14:8081/repository/maven-releases/")
|
||||||
implementation("com.squareup.moshi:moshi:1.15.2")
|
isAllowInsecureProtocol = true
|
||||||
implementation("androidx.work:work-runtime-ktx:2.11.0")
|
credentials {
|
||||||
implementation("androidx.room:room-runtime:2.8.4")
|
username = "admin"
|
||||||
implementation("androidx.room:room-ktx:2.8.4")
|
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
|
```kotlin
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -21,3 +21,9 @@ kotlin.code.style=official
|
||||||
# resources declared in the library itself and none from the library's dependencies,
|
# resources declared in the library itself and none from the library's dependencies,
|
||||||
# thereby reducing the size of the R class for that library
|
# 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
|
||||||
|
|
|
||||||
|
|
@ -40,5 +40,3 @@ android-application = { id = "com.android.application", version.ref = "agp" }
|
||||||
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
|
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
|
||||||
android-library = { id = "com.android.library", version.ref = "agp" }
|
android-library = { id = "com.android.library", version.ref = "agp" }
|
||||||
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
|
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
|
||||||
maven-publish = { id = "maven-publish" }
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,21 @@
|
||||||
import org.gradle.api.tasks.Delete
|
import org.gradle.api.publish.maven.MavenPublication
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
alias(libs.plugins.android.library)
|
alias(libs.plugins.android.library)
|
||||||
alias(libs.plugins.kotlin.android)
|
alias(libs.plugins.kotlin.android)
|
||||||
alias(libs.plugins.ksp)
|
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 {
|
android {
|
||||||
namespace = "com.yuanxuan.tracking_point.library"
|
namespace = "com.yuanxuan.tracking_point.library"
|
||||||
|
|
@ -21,10 +30,10 @@ android {
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
debug {
|
debug {
|
||||||
buildConfigField("String", "BASE_URL", "\"http://192.168.2.7:18828\"")
|
buildConfigField("String", "BASE_URL", "\"${baseDebugUrl.get()}\"")
|
||||||
}
|
}
|
||||||
release {
|
release {
|
||||||
buildConfigField("String", "BASE_URL", "\"https://track.23544.com\"")
|
buildConfigField("String", "BASE_URL", "\"${baseReleaseUrl.get()}\"")
|
||||||
isMinifyEnabled = false
|
isMinifyEnabled = false
|
||||||
proguardFiles(
|
proguardFiles(
|
||||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||||
|
|
@ -37,10 +46,14 @@ android {
|
||||||
targetCompatibility = JavaVersion.VERSION_11
|
targetCompatibility = JavaVersion.VERSION_11
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
buildFeatures {
|
buildFeatures {
|
||||||
buildConfig = true
|
buildConfig = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
singleVariant("debug")
|
||||||
|
singleVariant("release")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
|
|
@ -51,6 +64,50 @@ ksp {
|
||||||
arg("room.schemaLocation", "$projectDir/schemas")
|
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 {
|
dependencies {
|
||||||
implementation(libs.androidx.core.ktx)
|
implementation(libs.androidx.core.ktx)
|
||||||
implementation(libs.androidx.work.ktx)
|
implementation(libs.androidx.work.ktx)
|
||||||
|
|
@ -64,42 +121,12 @@ dependencies {
|
||||||
ksp(libs.androidx.room.ksp)
|
ksp(libs.androidx.room.ksp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Task to clean the 'aar' directory
|
tasks.register("publishAll") {
|
||||||
tasks.register<Delete>("cleanAar") {
|
group = "publishing"
|
||||||
group = "build"
|
description = "Publish both Debug and Release artifacts to their repositories."
|
||||||
description = "Deletes the root 'aar' directory to ensure a clean build."
|
|
||||||
delete(rootProject.file("aar"))
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.register("buildAar") {
|
dependsOn(
|
||||||
group = "build"
|
"publishDebugPublicationToDebugRepoRepository",
|
||||||
description = "Cleans, builds, and copies release and debug AARs."
|
"publishReleasePublicationToReleaseRepoRepository"
|
||||||
|
|
||||||
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()
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue