Skip to content

Commit

Permalink
refactor: migrate Gradle Groovy to Gradle Kotlin DSL
Browse files Browse the repository at this point in the history
  • Loading branch information
bqliang committed Dec 6, 2022
1 parent eaea7ff commit ed2499b
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 158 deletions.
138 changes: 0 additions & 138 deletions app/build.gradle

This file was deleted.

111 changes: 111 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
val appVersionCode: Int by rootProject.extra
val appVersionName: String by rootProject.extra

@Suppress("DSL_SCOPE_VIOLATION") // https://youtrack.jetbrains.com/issue/KTIJ-19369
plugins {
alias(libs.plugins.android.application)
kotlin("android") // alias(libs.plugins.kotlin.android)
kotlin("kapt")
kotlin("plugin.serialization") // alias(libs.plugins.kotlinx.serialization)
alias(libs.plugins.secrets) // Secrets Gradle Plugin for Android: https://github.com/google/secrets-gradle-plugin
}

android {
namespace = "com.bqliang.leavesheet"
compileSdk = 33

defaultConfig {
applicationId = "com.bqliang.leavesheet"
minSdk = 26
targetSdk = 33
versionCode = appVersionCode
versionName = appVersionName

javaCompileOptions {
annotationProcessorOptions {
argument("room.schemaLocation", "$projectDir/schemas")
}
}
}

signingConfigs {
signingConfigs.create("release") {
storeFile = file("../key.jks")
storePassword = System.getenv("KEY_STORE_PASSWORD")
keyAlias = System.getenv("SIGNING_KEY_ALIAS")
keyPassword = System.getenv("KEY_PASSWORD")
}
}

buildTypes {
getByName("debug") {
isMinifyEnabled = false
applicationIdSuffix = ".debug"
versionNameSuffix = ".debug"
}
getByName("release") {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
)
signingConfig = signingConfigs.getByName(name)
}
}

applicationVariants.configureEach {
outputs.configureEach {
(this as? com.android.build.gradle.internal.api.ApkVariantOutputImpl)?.outputFileName =
"${rootProject.name}-${versionName}-${name/* variant name */}.apk"
}
}

buildFeatures {
dataBinding = true
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

kotlinOptions {
jvmTarget = "11"
}

sourceSets {
getByName("main") {
res {
val srcDirs = listOf(
"main",
"settings"
).map { "src/main/java/com/bqliang/leavesheet/$it/res" }.plus("src/main/res")
setSrcDirs(srcDirs)
}
}
}
}

dependencies {
implementation(libs.tencent.mmkv)
implementation(libs.timber)
implementation(libs.rikkaX.preference.simplemenu)
implementation(libs.bundles.rikkaX.html)
implementation(libs.kotlinX.serialization.json)
implementation(libs.kotlinX.coroutines.android)
implementation(libs.bundles.appCenter)
implementation(libs.xabaras.recyclerViewSwipeDecorator)
implementation(libs.faruktoptas.fancyShowCaseView)
implementation(libs.google.material)
implementation(libs.androidX.core)
implementation(libs.androidX.appCompat)
implementation(libs.androidX.activity)
implementation(libs.androidX.fragment)
implementation(libs.bundles.androidX.lifeCycle)
implementation(libs.androidX.constraintLayout)
implementation(libs.androidX.preference)
implementation(libs.androidX.splashScreen)
implementation(libs.androidX.swipeRefreshLayout)
implementation(libs.bundles.androidX.dataStore)
implementation(libs.bundles.androidX.room)
kapt(libs.androidX.room.compiler)
}
2 changes: 1 addition & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
# proguardFiles setting in build.gradle.kts.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
Expand Down
17 changes: 0 additions & 17 deletions build.gradle

This file was deleted.

19 changes: 19 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
@Suppress("DSL_SCOPE_VIOLATION") // https://youtrack.jetbrains.com/issue/KTIJ-19369
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlinx.serialization) apply false
}
extra.apply {
val gitCommitId = ProcessBuilder("git", "rev-parse", "--short", "HEAD").execute()
val gitCommitCount = ProcessBuilder("git", "rev-list", "--count", "HEAD").execute().toInt()
val gitTag = ProcessBuilder("git", "describe", "--tags", "--abbrev=0").execute().let { tag ->
if (tag.isEmpty()) "" else "$tag."
}
set("appVersionCode", gitCommitCount)
set("appVersionName", "${gitTag}r${gitCommitCount}.${gitCommitId}")
}

fun ProcessBuilder.execute() = this.start().inputStream.bufferedReader().readText().trim()
67 changes: 67 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[versions] # used to declare versions which can be referenced by dependencies
agp = "7.3.1"
kotlin = "1.7.21"
androidX-room = "2.4.3"
lifeCycle = "2.5.1"
appCenter = "5.0.0"


[plugins] # used to declare plugins
android-application = { id = "com.android.application", version.ref = "agp" }
android-library = { id = "com.android.library", version.ref = "agp" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
secrets = "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:2.0.1"
kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version = "1.7.21-1.0.8" }


[libraries] # used to declare the aliases to coordinates
gradlePlugin-android = { module = "com.android.tools.build:gradle", version.ref = "agp" }
gradlePlugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }

kotlinX-serialization-json = "org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1"
kotlinX-coroutines-android = "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4"

androidX-core = "androidx.core:core-ktx:1.9.0"
androidX-appCompat = "androidx.appcompat:appcompat:1.5.1"
androidX-constraintLayout = "androidx.constraintlayout:constraintlayout:2.1.4"
androidX-activity = "androidx.activity:activity-ktx:1.6.1"
androidX-fragment = "androidx.fragment:fragment-ktx:1.5.4"
androidX-preference = "androidx.preference:preference-ktx:1.2.0"
androidX-splashScreen = "androidx.core:core-splashscreen:1.0.0"
androidX-swipeRefreshLayout = "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"

androidX-room-compiler = { module = "androidx.room:room-compiler", version.ref = "androidX-room" }
androidX-room-ktx = { module = "androidx.room:room-ktx", version.ref = "androidX-room" }
androidX-room-runtime = { module = "androidx.room:room-runtime", version.ref = "androidX-room" }

androidX-lifeCycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "lifeCycle" }
androidX-lifeCycle-viewModel = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "lifeCycle" }
androidX-lifeCycle-livedata = { module = "androidx.lifecycle:lifecycle-livedata-ktx", version.ref = "lifeCycle" }

# Typed DataStore (Typed API surface, such as Proto)
androidX-dataStore = "androidx.datastore:datastore:1.0.0"
# Preferences DataStore (SharedPreferences like APIs)
androidX-dataStore-preferences = "androidx.datastore:datastore-preferences:1.0.0"

google-material = "com.google.android.material:material:1.7.0"
tencent-mmkv = "com.tencent:mmkv:1.2.14"
timber = "com.jakewharton.timber:timber:5.0.1"
xabaras-recyclerViewSwipeDecorator = "com.github.xabaras:RecyclerViewSwipeDecorator:1.4"
faruktoptas-FancyShowCaseView = "com.github.faruktoptas:FancyShowCaseView:1.3.9"

rikkaX-html = "dev.rikka.rikkax.html:html:1.1.2"
rikkaX-html-ktx = "dev.rikka.rikkax.html:html-ktx:1.1.2"
rikkaX-preference-simplemenu = "dev.rikka.rikkax.preference:simplemenu-preference:1.0.3"

appCenter-crashes = { module = "com.microsoft.appcenter:appcenter-crashes", version.ref = "appCenter" }
appCenter-analytics = { module = "com.microsoft.appcenter:appcenter-analytics", version.ref = "appCenter" }
appCenter-distribute = { module = "com.microsoft.appcenter:appcenter-distribute", version.ref = "appCenter" }


[bundles] # used to declare dependency bundles
androidX-room = ["androidX-room-runtime", "androidX-room-ktx"]
appCenter = ["appCenter-crashes", "appCenter-analytics", "appCenter-distribute"]
rikkaX-html = ["rikkaX-html", "rikkaX-html-ktx"]
androidX-lifeCycle = ["androidX-lifeCycle-runtime", "androidX-lifeCycle-viewModel", "androidX-lifeCycle-livedata"]
androidX-dataStore = ["androidX-dataStore", "androidX-dataStore-preferences"]
4 changes: 2 additions & 2 deletions settings.gradle → settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' } //增加 jitPack Maven 仓库
maven("https://jitpack.io") //增加 jitPack Maven 仓库
}
}
rootProject.name = "Leave Sheet"
include ':app'
include(":app")

0 comments on commit ed2499b

Please sign in to comment.