From fd79c4ef0dd27955ce8f9f0b64d97b3a03d5050c Mon Sep 17 00:00:00 2001 From: fankesyooni Date: Fri, 22 Sep 2023 17:00:04 +0800 Subject: [PATCH] chore: migrate build script from groovy to kts - using SweetDependency, SweetProperty - using new maven publish function - update gradle and dependencies --- build.gradle | 63 ---------- build.gradle.kts | 5 + demo-app/build.gradle | 57 --------- gradle.properties | 47 ++++---- .../sweet-dependency-config.yaml | 52 ++++++++ gradle/wrapper/gradle-wrapper.properties | 5 +- samples/demo-android/build.gradle.kts | 52 ++++++++ settings.gradle | 17 --- settings.gradle.kts | 27 +++++ yukireflection-core/build.gradle.kts | 67 +++++++++++ yukireflection/build.gradle | 111 ------------------ 11 files changed, 232 insertions(+), 271 deletions(-) delete mode 100644 build.gradle create mode 100644 build.gradle.kts delete mode 100644 demo-app/build.gradle create mode 100644 gradle/sweet-dependency/sweet-dependency-config.yaml create mode 100644 samples/demo-android/build.gradle.kts delete mode 100644 settings.gradle create mode 100644 settings.gradle.kts create mode 100644 yukireflection-core/build.gradle.kts delete mode 100644 yukireflection/build.gradle diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 9a55254..0000000 --- a/build.gradle +++ /dev/null @@ -1,63 +0,0 @@ -import groovy.json.JsonSlurper - -plugins { - id 'com.android.application' version '7.4.1' apply false - id 'com.android.library' version '7.4.1' apply false - id 'org.jetbrains.kotlin.android' version '1.8.20' apply false - id 'org.jetbrains.kotlin.jvm' version '1.8.20' apply false -} - -ext { - android = [ - compileSdk: 33, - minSdk : 21, - targetSdk : 33 - ] - app = [ - versionName: 'universal', - versionCode: 1 - ] - maven = [ - developer : [ - id : '0', - user : 'fankesyooni', - email: 'qzmmcn@163.com' - ], - repository : [ - groupId : 'com.highcapable.yukireflection', - apiVersion : [ - name: '1.0.2', - code: 3 - ], - 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' - ] - ] -} - -/** - * 获取 Maven 授权信息 - 用于 Maven 的提交 - * @param childProjectDir 子项目的目录 - * @return [Object] - */ -@SuppressWarnings('unused') -static Object getMavenCredentials(File childProjectDir) { - def slurper = new JsonSlurper() - try { - return slurper.parse(new File("${childProjectDir.getParent()}/.maven/credentials.json")) - } catch (Throwable ignored) { - return slurper.parseText('{"username":"-NEEDED-","password":"-NEEDED-"}') - } -} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..7b776e9 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,5 @@ +plugins { + autowire(libs.plugins.android.application) apply false + autowire(libs.plugins.kotlin.jvm) apply false + autowire(libs.plugins.kotlin.android) apply false +} \ No newline at end of file diff --git a/demo-app/build.gradle b/demo-app/build.gradle deleted file mode 100644 index 3027461..0000000 --- a/demo-app/build.gradle +++ /dev/null @@ -1,57 +0,0 @@ -plugins { - id 'com.android.application' - id 'org.jetbrains.kotlin.android' -} - -android { - namespace 'com.highcapable.yukireflection.demo_app' - compileSdk rootProject.ext.android.compileSdk - - defaultConfig { - applicationId 'com.highcapable.yukireflection.demo_app' - - 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 { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_11 - targetCompatibility JavaVersion.VERSION_11 - } - kotlinOptions { - jvmTarget = '11' - freeCompilerArgs = [ - '-Xno-param-assertions', - '-Xno-call-assertions', - '-Xno-receiver-assertions' - ] - } - lintOptions { - checkReleaseBuilds false - } - buildFeatures { - viewBinding true - } -} - -dependencies { - implementation project(':yukireflection') - implementation 'androidx.core:core-ktx:1.10.0' - implementation 'androidx.appcompat:appcompat:1.6.1' - implementation 'com.google.android.material:material:1.8.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.4' - testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.1.5' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' -} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 3c5031e..dc1bf19 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,23 +1,30 @@ -# Project-wide Gradle settings. -# IDE (e.g. Android Studio) users: -# Gradle settings configured through the IDE *will override* -# any settings specified in this file. -# For more details on how to configure your build environment visit -# http://www.gradle.org/docs/current/userguide/build_environment.html -# Specifies the JVM arguments used for the daemon process. -# The setting is particularly useful for tweaking memory settings. +# Compiler Configuration org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. More details, visit -# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true -# AndroidX package structure to make it clearer which packages are bundled with the -# Android operating system, and which are packaged with your app's APK -# https://developer.android.com/topic/libraries/support-library/androidx-rn android.useAndroidX=true -# Kotlin code style for this project: "official" or "obsolete": +android.nonTransitiveRClass=true 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 \ No newline at end of file +kotlin.incremental.useClasspathSnapshot=true +# Project Configuration +project.name=YukiReflection +project.description=An efficient Reflection API for Java and Android built in Kotlin. +project.url=https://github.com/fankes/YukiReflection +project.groupName=com.highcapable.yukireflection +project.yukireflection-core.moduleName=api +project.yukireflection-core.version="1.0.2" +project.yukireflection-core.kotlin-optIn.YukiPrivateApi=${project.groupName}.annotation.YukiPrivateApi +project.licence.name=MIT +project.licence.url=https://github.com/fankes/YukiReflection/blob/master/LICENSE +project.developer.id="0" +project.developer.name=fankes +project.developer.email=qzmmcn@163.com +project.android.compileSdk=34 +project.android.minSdk=21 +project.android.targetSdk=34 +project.samples-demo-android.packageName=${project.groupName}.demo_app +project.samples-demo-android.versionName=universal +project.samples-demo-android.versionCode=1 +project.samples-demo-jvm.groupName=${project.groupName}.demo_jvm +# Maven Publish Configuration +maven.publish.scm.connection=scm:git:git://github.com/fankes/YukiReflection.git +maven.publish.scm.developerConnection=scm:git:ssh://github.com/fankes/YukiReflection.git +maven.publish.scm.url=https://github.com/fankes/YukiReflection \ No newline at end of file diff --git a/gradle/sweet-dependency/sweet-dependency-config.yaml b/gradle/sweet-dependency/sweet-dependency-config.yaml new file mode 100644 index 0000000..d808eee --- /dev/null +++ b/gradle/sweet-dependency/sweet-dependency-config.yaml @@ -0,0 +1,52 @@ +preferences: + autowire-on-sync-mode: UPDATE_OPTIONAL_DEPENDENCIES + repositories-mode: FAIL_ON_PROJECT_REPOS + +repositories: + gradle-plugin-portal: + scope: PLUGINS + google: + maven-central: + +plugins: + org.jetbrains.kotlin.jvm: + alias: kotlin-jvm + version: 1.9.10 + org.jetbrains.kotlin.android: + alias: kotlin-android + version-ref: kotlin-jvm + org.jetbrains.compose: + alias: kotlin-compose + version: 1.5.1 + com.android.application: + alias: android-application + version: 8.1.1 + com.vanniktech.maven.publish: + alias: maven-publish + version: 0.25.3 + +libraries: + org.jetbrains.compose.material3: + material3-desktop: + version: 1.5.1 + androidx.core: + core-ktx: + version: 1.10.0 + androidx.appcompat: + appcompat: + version: 1.6.1 + com.google.android.material: + material: + version: 1.8.0 + androidx.constraintlayout: + constraintlayout: + version: 2.1.4 + androidx.test.ext: + junit: + version: 1.1.5 + androidx.test.espresso: + espresso-core: + version: 3.5.1 + junit: + junit: + version: 4.13.2 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 7c8e6ae..692fc5c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Sat Jan 21 10:47:38 CST 2023 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME +zipStoreBase=GRADLE_USER_HOME \ No newline at end of file diff --git a/samples/demo-android/build.gradle.kts b/samples/demo-android/build.gradle.kts new file mode 100644 index 0000000..2aa4d86 --- /dev/null +++ b/samples/demo-android/build.gradle.kts @@ -0,0 +1,52 @@ +plugins { + autowire(libs.plugins.android.application) + autowire(libs.plugins.kotlin.android) +} + +android { + namespace = property.project.samples.demo.android.packageName + compileSdk = property.project.android.compileSdk + + defaultConfig { + applicationId = property.project.samples.demo.android.packageName + minSdk = property.project.android.minSdk + targetSdk = property.project.android.targetSdk + versionName = property.project.samples.demo.android.versionName + versionCode = property.project.samples.demo.android.versionCode + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + isMinifyEnabled = false + proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + kotlinOptions { + jvmTarget = "17" + freeCompilerArgs = listOf( + "-Xno-param-assertions", + "-Xno-call-assertions", + "-Xno-receiver-assertions" + ) + } + buildFeatures { + buildConfig = true + viewBinding = true + } + lint { checkReleaseBuilds = false } +} + +dependencies { + implementation(projects.yukireflectionCore) + implementation(androidx.core.core.ktx) + implementation(androidx.appcompat.appcompat) + implementation(com.google.android.material.material) + implementation(androidx.constraintlayout.constraintlayout) + testImplementation(junit.junit) + androidTestImplementation(androidx.test.ext.junit) + androidTestImplementation(androidx.test.espresso.espresso.core) +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index b7c100b..0000000 --- a/settings.gradle +++ /dev/null @@ -1,17 +0,0 @@ -pluginManagement { - repositories { - google() - mavenCentral() - gradlePluginPortal() - } -} -dependencyResolutionManagement { - repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) - repositories { - google() - mavenCentral() - } -} -rootProject.name = "YukiReflection" -include ':demo-app' -include ':yukireflection' \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..f1ba3b2 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,27 @@ +enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") +pluginManagement { + repositories { + gradlePluginPortal() + google() + mavenCentral() + } +} +plugins { + id("com.highcapable.sweetdependency") version "1.0.1" + id("com.highcapable.sweetproperty") version "1.0.2" +} +sweetProperty { + global { + sourcesCode { + includeKeys("^project\\..*\$".toRegex()) + isEnableRestrictedAccess = true + } + } + rootProject { all { isEnable = false } } + project("samples:demo-android") { sourcesCode { isEnable = false } } + project("samples:demo-jvm") { sourcesCode { isEnable = false } } + project("yukireflection-core") { sourcesCode { className = rootProject.name } } +} +rootProject.name = "YukiReflection" +include(":samples:demo-android", ":samples:demo-jvm") +include(":yukireflection-core") \ No newline at end of file diff --git a/yukireflection-core/build.gradle.kts b/yukireflection-core/build.gradle.kts new file mode 100644 index 0000000..1b00042 --- /dev/null +++ b/yukireflection-core/build.gradle.kts @@ -0,0 +1,67 @@ +plugins { + autowire(libs.plugins.kotlin.jvm) + autowire(libs.plugins.maven.publish) +} + +group = property.project.groupName + +java { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} + +kotlin { + sourceSets { + all { + languageSettings { + optIn(property.project.yukireflection.core.kotlin.optIn.yukiPrivateApi) + } + } + } +} + +tasks.withType().configureEach { + kotlinOptions { + jvmTarget = "17" + freeCompilerArgs = listOf( + "-opt-in=${property.project.yukireflection.core.kotlin.optIn.yukiPrivateApi}", + "-Xno-param-assertions", + "-Xno-call-assertions", + "-Xno-receiver-assertions" + ) + } +} + +dependencies { + compileOnly(files("libs/android-34.jar")) +} + +mavenPublishing { + coordinates(property.project.groupName, property.project.yukireflection.core.moduleName, property.project.yukireflection.core.version) + pom { + name = property.project.name + description = property.project.description + url = property.project.url + licenses { + license { + name = property.project.licence.name + url = property.project.licence.url + distribution = property.project.licence.url + } + } + developers { + developer { + id = property.project.developer.id + name = property.project.developer.name + email = property.project.developer.email + } + } + scm { + url = property.maven.publish.scm.url + connection = property.maven.publish.scm.connection + developerConnection = property.maven.publish.scm.developerConnection + } + } + publishToMavenCentral(com.vanniktech.maven.publish.SonatypeHost.S01) + signAllPublications() +} \ No newline at end of file diff --git a/yukireflection/build.gradle b/yukireflection/build.gradle deleted file mode 100644 index 3ca00f0..0000000 --- a/yukireflection/build.gradle +++ /dev/null @@ -1,111 +0,0 @@ -plugins { - id 'com.android.library' - id 'org.jetbrains.kotlin.android' - id 'maven-publish' - id 'signing' -} - -android { - namespace 'com.highcapable.yukireflection' - compileSdk rootProject.ext.android.compileSdk - - defaultConfig { - 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' - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_11 - targetCompatibility JavaVersion.VERSION_11 - } - kotlinOptions { - jvmTarget = '11' - freeCompilerArgs = [ - '-opt-in=com.highcapable.yukireflection.annotation.YukiPrivateApi', - '-Xno-param-assertions', - '-Xno-call-assertions', - '-Xno-receiver-assertions' - ] - } - lintOptions { - checkReleaseBuilds false - } - publishing { - singleVariant('release') { - withSourcesJar() - withJavadocJar() - } - } -} - -kotlin { sourceSets { all { languageSettings { optIn('com.highcapable.yukireflection.annotation.YukiPrivateApi') } } } } - -dependencies { - implementation 'androidx.core:core-ktx:1.10.0' - implementation 'androidx.appcompat:appcompat:1.6.1' -} - -tasks.register('androidSourcesJar', Jar) { - archiveClassifier.set('sources') - from android.sourceSets.main.java.srcDirs -} - -group = rootProject.ext.maven.repository.groupId -version = rootProject.ext.maven.repository.apiVersion.name - -publishing { - publications { - release(MavenPublication) { - artifactId = 'api' - artifact "$buildDir/outputs/aar/${project.name}-release.aar" - artifact androidSourcesJar - pom { - name = rootProject.ext.maven.repository.name - description = rootProject.ext.maven.repository.description - url = rootProject.ext.maven.repository.website - licenses { - license { - name = rootProject.ext.maven.repository.licence.name - url = rootProject.ext.maven.repository.licence.url - } - } - developers { - developer { - id = rootProject.ext.maven.developer.id - name = rootProject.ext.maven.developer.user - email = rootProject.ext.maven.developer.email - } - } - scm { - connection = rootProject.ext.maven.configurations.githubConnection - developerConnection = rootProject.ext.maven.configurations.githubDeveloperConnection - url = rootProject.ext.maven.configurations.githubUrl - } - } - } - } - repositories { - maven { - name = rootProject.ext.maven.configurations.ossName - url = rootProject.ext.maven.configurations.ossUrl - credentials { - def configs = getMavenCredentials(projectDir) - username = configs.username - password = configs.password - } - } - } -} - -signing { sign publishing.publications } \ No newline at end of file