From b7c0bc874c470bab3d95bf910b7cbf45445533d5 Mon Sep 17 00:00:00 2001 From: James Rich <2199651+jamesarich@users.noreply.github.com> Date: Mon, 26 May 2025 21:26:46 -0500 Subject: [PATCH] chore(build): Refactor Gradle build scripts to Kotlin DSL (#1944) --- .github/workflows/android.yml | 2 +- .github/workflows/release.yml | 6 +-- .gitignore | 1 + app/build.gradle | 14 +++---- build.gradle | 51 ------------------------- build.gradle.kts | 59 +++++++++++++++++++++++++++++ buildSrc/build.gradle.kts | 24 ++++++++++++ buildSrc/src/main/kotlin/Configs.kt | 26 +++++++++++++ settings.gradle | 3 -- settings.gradle.kts | 19 ++++++++++ 10 files changed, 140 insertions(+), 65 deletions(-) delete mode 100644 build.gradle create mode 100644 build.gradle.kts create mode 100644 buildSrc/build.gradle.kts create mode 100644 buildSrc/src/main/kotlin/Configs.kt delete mode 100644 settings.gradle create mode 100644 settings.gradle.kts diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 08e819a30..7e2ed63fc 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -103,7 +103,7 @@ jobs: timeout-minutes: 30 strategy: matrix: - api-level: [26, 34] + api-level: [26, 35] steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ba7c05642..6f74f8c84 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,8 +18,8 @@ jobs: - name: Get `versionCode` & `versionName` run: | - echo "versionCode=$(grep -oP 'versionCode \K\d+' ./app/build.gradle)" >> $GITHUB_ENV - echo "versionName=$(grep -oP 'versionName \"\K[^\"]+' ./app/build.gradle)" >> $GITHUB_ENV + echo "versionCode=$(grep -oP 'VERSION_CODE = \K\d+' ./buildSrc/src/main/kotlin/Configs.kt)" >> $GITHUB_ENV + echo "versionName=$(grep -oP 'VERSION_NAME = \"\K[^\"]+' ./buildSrc/src/main/kotlin/Configs.kt)" >> $GITHUB_ENV - name: Validate Gradle wrapper uses: gradle/actions/wrapper-validation@v4 @@ -48,7 +48,7 @@ jobs: run: ./gradlew assembleFdroidRelease - name: Enable Crashlytics - run: sed -i 's/useCrashlytics = false/useCrashlytics = true/g' ./build.gradle + run: sed -i 's/USE_CRASHLYTICS = false/USE_CRASHLYTICS = true/g' ./buildSrc/src/main/kotlin/Configs.kt - name: Build Play Store release run: ./gradlew bundleGoogleRelease assembleGoogleRelease diff --git a/.gitignore b/.gitignore index bc8516d49..610cbc7b6 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ .externalNativeBuild .cxx /app/release +/buildSrc/build # Java KeyStore certificates *.jks diff --git a/app/build.gradle b/app/build.gradle index 2cf783ea5..a91377a43 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -27,13 +27,13 @@ android { storePassword keystoreProperties['storePassword'] } } - compileSdk 36 + compileSdk Configs.COMPILE_SDK defaultConfig { - applicationId "com.geeksville.mesh" - minSdkVersion 23 - targetSdk 36 - versionCode 30603 // format is Mmmss (where M is 1+the numeric major number - versionName "2.6.3" + applicationId Configs.APPLICATION_ID + minSdkVersion Configs.MIN_SDK_VERSION + targetSdk Configs.TARGET_SDK + versionCode Configs.VERSION_CODE // format is Mmmss (where M is 1+the numeric major number + versionName Configs.VERSION_NAME testInstrumentationRunner "com.geeksville.mesh.TestRunner" // per https://developer.android.com/studio/write/vector-asset-studio @@ -49,7 +49,7 @@ android { } google { dimension = 'default' - if (useCrashlytics) { + if (Configs.USE_CRASHLYTICS) { apply plugin: 'com.google.gms.google-services' apply plugin: 'com.google.firebase.crashlytics' } diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 5c2aa7208..000000000 --- a/build.gradle +++ /dev/null @@ -1,51 +0,0 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - -buildscript { - ext { - useCrashlytics = false - } - - repositories { - google() - mavenCentral() - } - dependencies { - classpath libs.agp - classpath libs.kotlin.gradle.plugin - classpath libs.kotlin.serialization - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - - // Firebase Crashlytics - if (useCrashlytics) { - classpath libs.google.services - classpath libs.firebase.crashlytics.gradle - } - - // protobuf plugin - docs here https://github.com/google/protobuf-gradle-plugin - classpath libs.protobuf.gradle.plugin - - classpath libs.hilt.android.gradle.plugin - } -} - -plugins { - alias (libs.plugins.kotlin.jvm) apply false - alias (libs.plugins.devtools.ksp) apply false - alias (libs.plugins.compose) apply false -} - -allprojects { - repositories { - google() - mavenCentral() - // jcenter() - maven { url 'https://jitpack.io' } - //maven { url "https://plugins.gradle.org/m2/" } - } -} - -task clean(type: Delete) { - delete rootProject.buildDir -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 000000000..04b2a989b --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2025 Meshtastic LLC + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +buildscript { + repositories { + google() + mavenCentral() + } + dependencies { + classpath(libs.agp) + classpath(libs.kotlin.gradle.plugin) + classpath(libs.kotlin.serialization) + + // Google Play Services and Firebase Crashlytics + // If you want to use Firebase Crashlytics, + // set Configs.USE_CRASHLYTICS to true in: + // buildSrc/src/main/kotlin/Configs.kt + // Disabled by default for fdroid builds + if (Configs.USE_CRASHLYTICS) { + classpath(libs.google.services) + classpath(libs.firebase.crashlytics.gradle) + } + + classpath(libs.protobuf.gradle.plugin) + classpath(libs.hilt.android.gradle.plugin) + } +} + +plugins { + alias(libs.plugins.kotlin.jvm) apply false + alias(libs.plugins.devtools.ksp) apply false + alias(libs.plugins.compose) apply false +} + +allprojects { + repositories { + google() + mavenCentral() + maven { url = uri("https://jitpack.io") } + } +} + +tasks.register("clean") { + delete(layout.buildDirectory) +} diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 000000000..1a66d3ac7 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Meshtastic LLC + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +plugins { + `kotlin-dsl` +} + +repositories { + mavenCentral() +} diff --git a/buildSrc/src/main/kotlin/Configs.kt b/buildSrc/src/main/kotlin/Configs.kt new file mode 100644 index 000000000..f67ce87b6 --- /dev/null +++ b/buildSrc/src/main/kotlin/Configs.kt @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2025 Meshtastic LLC + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +object Configs { + const val APPLICATION_ID = "com.geeksville.mesh" + const val MIN_SDK_VERSION = 23 + const val TARGET_SDK = 36 + const val COMPILE_SDK = 36 + const val VERSION_CODE = 30603 // format is Mmmss (where M is 1+the numeric major number + const val VERSION_NAME = "2.6.3" + const val USE_CRASHLYTICS = true // Set to false if you don't want to use Firebase Crashlytics +} diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 4f6c8c362..000000000 --- a/settings.gradle +++ /dev/null @@ -1,3 +0,0 @@ -include ':app' -rootProject.name='Meshtastic Android' -include ':network' diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 000000000..972e2ae23 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Meshtastic LLC + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +include(":app", ":network") +rootProject.name = "Meshtastic Android"