From 4cef17c9ab538668c5e42630c0c9a8ce9635aa14 Mon Sep 17 00:00:00 2001 From: IndusAryan <125901294+IndusAryan@users.noreply.github.com> Date: Tue, 12 Sep 2023 15:16:58 +0530 Subject: [PATCH] chore: migrate gradle from groovy to kotlin dsl (buildscripts) (#4758) Co-authored-by: IndusAryan --- app/build.gradle | 134 ------------------------- app/build.gradle.kts | 131 ++++++++++++++++++++++++ app/proguard-rules.pro | 2 +- build.gradle | 29 ------ build.gradle.kts | 25 +++++ settings.gradle => settings.gradle.kts | 11 +- 6 files changed, 159 insertions(+), 173 deletions(-) delete mode 100644 app/build.gradle create mode 100644 app/build.gradle.kts delete mode 100644 build.gradle create mode 100644 build.gradle.kts rename settings.gradle => settings.gradle.kts (57%) diff --git a/app/build.gradle b/app/build.gradle deleted file mode 100644 index 16885d44d..000000000 --- a/app/build.gradle +++ /dev/null @@ -1,134 +0,0 @@ -import java.time.Instant - -plugins { - id 'com.android.application' - id 'com.google.devtools.ksp' - id 'kotlin-android' - id 'kotlinx-serialization' - id 'kotlin-parcelize' -} - -android { - compileSdk 34 - - defaultConfig { - applicationId 'com.github.libretube' - minSdk 21 - targetSdk 33 - versionCode 40 - versionName '0.17.1' - testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' - resValue "string", "app_name", "LibreTube" - - ksp { - arg("room.schemaLocation", "$projectDir/schemas") - arg("exportSchema", "true") - } - } - - buildFeatures { - viewBinding true - } - - applicationVariants.configureEach { variant -> - // use the date as version for debug builds - if (variant.name == 'debug') { - variant.outputs.each { output -> - output.versionCodeOverride = getUnixTime() - } - } - } - - buildTypes { - release { - minifyEnabled true - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - - debug { - debuggable true - applicationIdSuffix ".debug" - resValue "string", "app_name", "LibreTube Debug" - } - } - compileOptions { - coreLibraryDesugaringEnabled true - sourceCompatibility JavaVersion.VERSION_17 - targetCompatibility JavaVersion.VERSION_17 - } - kotlinOptions { - jvmTarget = JavaVersion.VERSION_17 - } - splits { - abi { - enable true - reset() - include "armeabi-v7a", "arm64-v8a", "x86", "x86_64" - universalApk true - - } - } - packagingOptions { - jniLibs { - excludes += ['lib/armeabi-v7a/*_neon.so'] - } - } - namespace 'com.github.libretube' -} - -dependencies { - //debugImplementation libs.square.leakcanary - - /* Android Core */ - implementation libs.androidx.activity - implementation libs.androidx.appcompat - implementation libs.androidx.core - implementation libs.androidx.constraintlayout - implementation libs.androidx.fragment - implementation libs.androidx.legacySupport - implementation libs.androidx.navigation.fragment - implementation libs.androidx.navigation.ui - implementation libs.androidx.preference - implementation libs.androidx.work.runtime - - /* Android Lifecycle */ - implementation libs.lifecycle.viewmodel - implementation libs.lifecycle.runtime - implementation libs.lifecycle.livedata - implementation libs.lifecycle.service - - /* Testing */ - androidTestImplementation libs.androidx.test.junit - androidTestImplementation libs.androidx.test.espressoCore - - /* Design */ - implementation libs.material - - /* ExoPlayer */ - implementation libs.androidx.media3.exoplayer - implementation libs.androidx.media3.ui - implementation libs.androidx.media3.exoplayer.hls - implementation libs.androidx.media3.exoplayer.dash - implementation libs.androidx.media3.session - implementation(libs.androidx.media3.datasource.cronet) { exclude group: 'com.google.android.gms' } - - /* Retrofit and Kotlinx Serialization */ - implementation libs.square.retrofit - implementation libs.kotlinx.serialization - implementation libs.kotlinx.datetime - implementation libs.kotlinx.serialization.retrofit - - /* Cronet and Coil */ - coreLibraryDesugaring libs.desugaring - implementation libs.cronet.embedded - implementation libs.cronet.okhttp - implementation libs.coil - - /* Room */ - ksp libs.room.compiler - implementation libs.room -} - -static def getUnixTime() { - return Instant.now().getEpochSecond() -} diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 000000000..6a8915c0e --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,131 @@ +import java.time.Instant + +plugins { + id("com.android.application") + id("com.google.devtools.ksp") + id("kotlin-android") + id("kotlinx-serialization") + id("kotlin-parcelize") +} + +android { + compileSdk = 34 + + defaultConfig { + applicationId = "com.github.libretube" + minSdk = 21 + targetSdk = 33 + versionCode = 40 + versionName = "0.17.1" + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + resValue("string", "app_name", "LibreTube") + + ksp { + arg("room.schemaLocation", "$projectDir/schemas") + arg("exportSchema", "true") + } + } + + viewBinding { + enable = true + } + + buildTypes { + getByName("release") { + isMinifyEnabled = true + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + + getByName("debug") { + isDebuggable = true + applicationIdSuffix = ".debug" + resValue("string", "app_name", "LibreTube Debug") + } + } + + compileOptions { + isCoreLibraryDesugaringEnabled = true + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + + kotlinOptions { + jvmTarget = "17" + } + + splits { + abi { + isEnable = true + reset() + include("armeabi-v7a", "arm64-v8a", "x86", "x86_64") + isUniversalApk = true + } + } + + packagingOptions { + exclude("lib/armeabi-v7a/*_neon.so") + } + + namespace = "com.github.libretube" + + tasks.register("testClasses") +} + +dependencies { + // debugImplementation libs.square.leakcanary + /* Android Core */ + implementation(libs.androidx.activity) + implementation(libs.androidx.appcompat) + implementation(libs.androidx.core) + implementation(libs.androidx.constraintlayout) + implementation(libs.androidx.fragment) + implementation(libs.androidx.legacySupport) + implementation(libs.androidx.navigation.fragment) + implementation(libs.androidx.navigation.ui) + implementation(libs.androidx.preference) + implementation(libs.androidx.work.runtime) + + /* Android Lifecycle */ + implementation(libs.lifecycle.viewmodel) + implementation(libs.lifecycle.runtime) + implementation(libs.lifecycle.livedata) + implementation(libs.lifecycle.service) + + /* Testing */ + androidTestImplementation(libs.androidx.test.junit) + androidTestImplementation(libs.androidx.test.espressoCore) + + /* Design */ + implementation(libs.material) + + /* ExoPlayer */ + implementation(libs.androidx.media3.exoplayer) + implementation(libs.androidx.media3.ui) + implementation(libs.androidx.media3.exoplayer.hls) + implementation(libs.androidx.media3.exoplayer.dash) + implementation(libs.androidx.media3.session) + implementation(libs.androidx.media3.datasource.cronet) { + exclude(group = "com.google.android.gms") + } + + /* Retrofit and Kotlinx Serialization */ + implementation(libs.square.retrofit) + implementation(libs.kotlinx.serialization) + implementation(libs.kotlinx.datetime) + implementation(libs.kotlinx.serialization.retrofit) + + /* Cronet and Coil */ + coreLibraryDesugaring(libs.desugaring) + implementation(libs.cronet.embedded) + implementation(libs.cronet.okhttp) + implementation(libs.coil) + + /* Room */ + ksp(libs.room.compiler) + implementation(libs.room) +} + +fun getUnixTime() = Instant.now().epochSecond diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index b6c1bdb45..9594cae63 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -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 diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 141415945..000000000 --- a/build.gradle +++ /dev/null @@ -1,29 +0,0 @@ -//plugins { - // id 'com.android.application' apply false version '7.2.1' - //id 'org.jetbrains.kotlin.android' apply false version '1.7.0' -//} - -// Top-level build file where you can add configuration options common to all sub-projects/modules. -buildscript { - ext.kotlin_version = '1.8.22' - repositories { - google() - mavenCentral() - } - dependencies { - classpath libs.gradle - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - } -} - -plugins { - id 'com.google.devtools.ksp' version '1.9.0-1.0.12' apply false -} - -task clean(type: Delete) { - delete rootProject.buildDir -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 000000000..07b0b778f --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,25 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + val kotlinVersion = "1.8.22" + repositories { + google() + mavenCentral() + } + dependencies { + classpath(libs.gradle) + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") + classpath("org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion") + + // NOTE: Do not place your application dependencies here, they belong + // to the individual module build.gradle files + } +} + +plugins { + id("com.google.devtools.ksp") version("1.9.0-1.0.12") apply false +} + +tasks.register("clean") { + delete(rootProject.buildDir) +} diff --git a/settings.gradle b/settings.gradle.kts similarity index 57% rename from settings.gradle rename to settings.gradle.kts index 8ef48f67a..8d402db63 100644 --- a/settings.gradle +++ b/settings.gradle.kts @@ -1,11 +1,3 @@ -//pluginManagement { - // repositories { - //gradlePluginPortal() - // google() - // mavenCentral() - // } -//} - dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { @@ -15,4 +7,5 @@ dependencyResolutionManagement { } rootProject.name = "LibreTube" -include ':app' + +include(":app")