From f516f2de525c52e27a8bb327fb4ac9f63e30e4a6 Mon Sep 17 00:00:00 2001 From: fankesyooni Date: Sun, 16 Apr 2023 00:12:35 +0800 Subject: [PATCH] Modify merge contents of build.gradle into constant definitions --- build.gradle | 52 +++++++++++++------ demo-app/build.gradle | 16 +++--- yukireflection/build.gradle | 39 +++++++------- .../yukireflection/YukiReflection.kt | 4 +- 4 files changed, 69 insertions(+), 42 deletions(-) diff --git a/build.gradle b/build.gradle index ef6255e..3d2d467 100644 --- a/build.gradle +++ b/build.gradle @@ -8,21 +8,43 @@ plugins { } ext { - devId = "0" - devUser = "fankesyooni" - userEmail = "qzmmcn@163.com" - groupId = "com.highcapable.yukireflection" - apiVersion = "1.0.0" - repoName = "YukiReflection" - repoDescription = "An efficient Reflection API for the Android platform built in Kotlin." - licenceName = "MIT License" - licenceUrl = "https://github.com/fankes/YukiReflection/blob/master/LICENSE" - website = "https://github.com/fankes/YukiReflection" - githubConnection = "scm:git:git://github.com/path/to/repo.git" - githubDeveloperConnection = "scm:git:ssh://github.com/path/to/repo.git" - githubUrl = "https://github.com/path/to/repo" - ossName = "OSSRH" - ossUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" + android = [ + compileSdk: 33, + minSdk : 21, + targetSdk : 33 + ] + app = [ + versionName: '1.0.0', + versionCode: 1 + ] + maven = [ + developer : [ + id : '0', + user : 'fankesyooni', + email: 'qzmmcn@163.com' + ], + repository : [ + groupId : 'com.highcapable.yukireflection', + apiVersion : [ + name: '1.0.0', + code: 1 + ], + name : 'YukiReflection', + description: 'An efficient Reflection API for the Android platform built in Kotlin.', + website : 'https://github.com/fankes/YukiReflection', + licence : [ + name: 'MIT License', + url : 'https://github.com/fankes/YukiReflection/blob/master/LICENSE' + ] + ], + configurations: [ + githubConnection : 'scm:git:git://github.com/path/to/repo.git', + githubDeveloperConnection: 'scm:git:ssh://github.com/path/to/repo.git', + githubUrl : 'https://github.com/path/to/repo', + ossName : 'OSSRH', + ossUrl : 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2' + ] + ] } /** diff --git a/demo-app/build.gradle b/demo-app/build.gradle index fa42d16..3027461 100644 --- a/demo-app/build.gradle +++ b/demo-app/build.gradle @@ -5,16 +5,18 @@ plugins { android { namespace 'com.highcapable.yukireflection.demo_app' - compileSdk 33 + compileSdk rootProject.ext.android.compileSdk defaultConfig { - applicationId "com.highcapable.yukireflection.demo_app" - minSdk 21 - targetSdk 33 - versionCode 1 - versionName "1.0" + applicationId 'com.highcapable.yukireflection.demo_app' - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + minSdk rootProject.ext.android.minSdk + targetSdk rootProject.ext.android.targetSdk + + versionCode rootProject.ext.app.versionCode + versionName rootProject.ext.app.versionName + + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' } buildTypes { diff --git a/yukireflection/build.gradle b/yukireflection/build.gradle index f7424bd..3ca00f0 100644 --- a/yukireflection/build.gradle +++ b/yukireflection/build.gradle @@ -7,11 +7,14 @@ plugins { android { namespace 'com.highcapable.yukireflection' - compileSdk 33 + compileSdk rootProject.ext.android.compileSdk defaultConfig { - minSdk 21 - targetSdk 33 + minSdk rootProject.ext.android.minSdk + targetSdk rootProject.ext.android.targetSdk + + buildConfigField('String', 'API_VERSION_NAME', "\"${rootProject.ext.maven.repository.apiVersion.name}\"") + buildConfigField('int', 'API_VERSION_CODE', "${rootProject.ext.maven.repository.apiVersion.code}") consumerProguardFiles 'consumer-rules.pro' } @@ -58,8 +61,8 @@ tasks.register('androidSourcesJar', Jar) { from android.sourceSets.main.java.srcDirs } -group = rootProject.ext.groupId -version = rootProject.ext.apiVersion +group = rootProject.ext.maven.repository.groupId +version = rootProject.ext.maven.repository.apiVersion.name publishing { publications { @@ -68,34 +71,34 @@ publishing { artifact "$buildDir/outputs/aar/${project.name}-release.aar" artifact androidSourcesJar pom { - name = rootProject.ext.repoName - description = rootProject.ext.repoDescription - url = rootProject.ext.website + name = rootProject.ext.maven.repository.name + description = rootProject.ext.maven.repository.description + url = rootProject.ext.maven.repository.website licenses { license { - name = rootProject.ext.licenceName - url = rootProject.ext.licenceUrl + name = rootProject.ext.maven.repository.licence.name + url = rootProject.ext.maven.repository.licence.url } } developers { developer { - id = rootProject.ext.devId - name = rootProject.ext.devUser - email = rootProject.ext.userEmail + id = rootProject.ext.maven.developer.id + name = rootProject.ext.maven.developer.user + email = rootProject.ext.maven.developer.email } } scm { - connection = rootProject.ext.githubConnection - developerConnection = rootProject.ext.githubDeveloperConnection - url = rootProject.ext.githubUrl + connection = rootProject.ext.maven.configurations.githubConnection + developerConnection = rootProject.ext.maven.configurations.githubDeveloperConnection + url = rootProject.ext.maven.configurations.githubUrl } } } } repositories { maven { - name = rootProject.ext.ossName - url = rootProject.ext.ossUrl + name = rootProject.ext.maven.configurations.ossName + url = rootProject.ext.maven.configurations.ossUrl credentials { def configs = getMavenCredentials(projectDir) username = configs.username diff --git a/yukireflection/src/main/java/com/highcapable/yukireflection/YukiReflection.kt b/yukireflection/src/main/java/com/highcapable/yukireflection/YukiReflection.kt index 40edb1d..fe352e6 100644 --- a/yukireflection/src/main/java/com/highcapable/yukireflection/YukiReflection.kt +++ b/yukireflection/src/main/java/com/highcapable/yukireflection/YukiReflection.kt @@ -47,10 +47,10 @@ import java.lang.reflect.Method object YukiReflection { /** 获取当前 [YukiReflection] 的版本 */ - const val API_VERSION_NAME = "1.0.0" + const val API_VERSION_NAME = BuildConfig.API_VERSION_NAME /** 获取当前 [YukiReflection] 的版本号 */ - const val API_VERSION_CODE = 1 + const val API_VERSION_CODE = BuildConfig.API_VERSION_CODE /** * 配置 [YukiReflection]