From 2b4b66fc8ce2278d7d0460d674c7d4bdd744baa5 Mon Sep 17 00:00:00 2001 From: Rafael Caetano Date: Mon, 26 Jul 2021 21:54:37 +0100 Subject: [PATCH] Migrate to Gradle Kotlin DSL --- app/build.gradle | 131 --------------------- app/build.gradle.kts | 144 +++++++++++++++++++++++ app/proguard-rules.pro | 2 +- build.gradle | 37 ------ build.gradle.kts | 31 +++++ buildSrc/build.gradle.kts | 7 ++ buildSrc/src/main/kotlin/AppConfig.kt | 9 ++ buildSrc/src/main/kotlin/Dependencies.kt | 75 ++++++++++++ 8 files changed, 267 insertions(+), 169 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 create mode 100644 buildSrc/build.gradle.kts create mode 100644 buildSrc/src/main/kotlin/AppConfig.kt create mode 100644 buildSrc/src/main/kotlin/Dependencies.kt diff --git a/app/build.gradle b/app/build.gradle deleted file mode 100644 index 6081443..0000000 --- a/app/build.gradle +++ /dev/null @@ -1,131 +0,0 @@ -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: 'kotlin-parcelize' -apply plugin: 'kotlin-kapt' -apply plugin: 'dagger.hilt.android.plugin' - -android { - compileSdkVersion 30 - ndkVersion '21.3.6528147' - defaultConfig { - applicationId "me.magnum.melonds" - minSdkVersion 21 - targetSdkVersion 30 - versionCode 17 - versionName "Beta 1.5.2" - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - externalNativeBuild { - cmake { - cppFlags "-std=c++17 -Wno-write-strings" - } - } - vectorDrawables.useSupportLibrary = true - } - kotlinOptions { - jvmTarget = "1.8" - freeCompilerArgs += "-Xopt-in=kotlin.ExperimentalUnsignedTypes" - } - buildFeatures { - viewBinding true - } - buildTypes { - release { - minifyEnabled true - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - debug { - applicationIdSuffix ".dev" - } - } - - flavorDimensions "version" - productFlavors { - playStore { - dimension "version" - versionNameSuffix " PS" - } - gitHub { - dimension "version" - versionNameSuffix " GH" - } - } - externalNativeBuild { - cmake { - path "CMakeLists.txt" - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - configurations.all { - resolutionStrategy.eachDependency { DependencyResolveDetails details -> - def requested = details.requested - if (requested.group == "com.android.support") { - if (!requested.name.startsWith("multidex")) { - details.useVersion "26.+" - } - } - } - } -} - -dependencies { - implementation fileTree(include: ['*.jar'], dir: 'libs') - - // Kotlin - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - - // AndroidX - implementation 'androidx.activity:activity-ktx:1.2.3' - implementation 'androidx.appcompat:appcompat:1.3.0' - implementation 'androidx.cardview:cardview:1.0.0' - implementation 'androidx.constraintlayout:constraintlayout:2.0.4' - implementation 'androidx.core:core-ktx:1.6.0' - implementation 'androidx.documentfile:documentfile:1.0.1' - implementation 'androidx.fragment:fragment-ktx:1.3.5' - implementation "androidx.hilt:hilt-work:$hiltx_version" - implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' - implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1' - implementation 'androidx.preference:preference-ktx:1.1.1' - implementation 'androidx.recyclerview:recyclerview:1.2.1' - implementation "androidx.room:room-runtime:$room_version" - implementation "androidx.room:room-rxjava2:$room_version" - implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' - implementation "androidx.work:work-runtime-ktx:$work_version" - implementation "androidx.work:work-rxjava2:$work_version" - implementation 'com.google.android.material:material:1.4.0' - - // Third-party - implementation 'com.github.svenoaks:MasterSwitchPreference:0.9.1' - implementation 'com.google.android:flexbox:2.0.1' - implementation 'com.google.code.gson:gson:2.8.6' - implementation "com.google.dagger:hilt-android:$hilt_version" - implementation 'com.squareup.picasso:picasso:2.71828' - implementation "io.noties.markwon:core:$markwon_version" - implementation "io.noties.markwon:image-picasso:$markwon_version" - implementation "io.noties.markwon:linkify:$markwon_version" - implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' - implementation 'io.reactivex.rxjava2:rxjava:2.2.10' - implementation 'org.apache.commons:commons-compress:1.21' - implementation 'org.tukaani:xz:1.9' - - // GitHub - gitHubImplementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit_version" - gitHubImplementation "com.squareup.retrofit2:converter-gson:$retrofit_version" - gitHubImplementation "com.squareup.retrofit2:retrofit:$retrofit_version" - - // KAPT - kapt "androidx.hilt:hilt-compiler:$hiltx_version" - kapt "androidx.room:room-compiler:$room_version" - kapt "com.google.dagger:hilt-android-compiler:$hilt_version" - - // Testing - testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' - androidTestImplementation 'androidx.test.ext:junit:1.1.1' -} - -repositories { - mavenCentral() -} diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..284f752 --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,144 @@ +plugins { + id("com.android.application") + id("kotlin-android") + id("kotlin-parcelize") + id("kotlin-kapt") + id("dagger.hilt.android.plugin") +} + +android { + compileSdkVersion(AppConfig.compileSdkVersion) + ndkVersion = AppConfig.ndkVersion + defaultConfig { + applicationId = "me.magnum.melonds" + minSdkVersion(AppConfig.minSdkVersion) + targetSdkVersion(AppConfig.targetSdkVersion) + versionCode = AppConfig.versionCode + versionName = AppConfig.versionName + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + externalNativeBuild { + cmake { + cppFlags("-std=c++17 -Wno-write-strings") + } + } + vectorDrawables.useSupportLibrary = true + } + kotlinOptions { + jvmTarget = "1.8" + freeCompilerArgs += "-Xopt-in=kotlin.ExperimentalUnsignedTypes" + } + buildFeatures { + viewBinding = true + } + buildTypes { + getByName("release") { + isMinifyEnabled = true + proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro") + } + getByName("debug") { + applicationIdSuffix = ".dev" + } + } + + flavorDimensions("version") + productFlavors { + create("playStore") { + dimension = "version" + versionNameSuffix = " PS" + } + create("gitHub") { + dimension = "version" + versionNameSuffix = " GH" + } + } + externalNativeBuild { + cmake { + path = file("CMakeLists.txt") + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + configurations.all { + resolutionStrategy.eachDependency { + val requested = requested + if (requested.group == "com.android.support") { + if (!requested.name.startsWith("multidex")) { + useVersion("26.+") + } + } + } + } +} + +dependencies { + val gitHubImplementation by configurations + + with(Dependencies.Kotlin) { + implementation(kotlinStdlib) + } + + // AndroidX + with(Dependencies.AndroidX) { + implementation(activity) + implementation(appCompat) + implementation(cardView) + implementation(constraintLayout) + implementation(core) + implementation(documentFile) + implementation(fragment) + implementation(hiltWork) + implementation(lifecycleExtensions) + implementation(lifecycleViewModel) + implementation(preference) + implementation(recyclerView) + implementation(room) + implementation(roomRxJava) + implementation(swipeRefreshLayout) + implementation(work) + implementation(workRxJava) + implementation(material) + } + + // Third-party + with(Dependencies.ThirdParty) { + implementation(masterSwitchPreference) + implementation(flexbox) + implementation(gson) + implementation(hilt) + implementation(picasso) + implementation(markwon) + implementation(markwonImagePicasso) + implementation(markwonLinkify) + implementation(rxJava) + implementation(rxJavaAndroid) + implementation(commonsCompress) + implementation(xz) + } + + // GitHub + with(Dependencies.GitHub) { + gitHubImplementation(retrofit) + gitHubImplementation(retrofitAdapterRxJava) + gitHubImplementation(retrofitConverterGson) + } + + // KAPT + with(Dependencies.Kapt) { + kapt(hiltCompiler) + kapt(hiltCompilerAndroid) + kapt(roomCompiler) + } + + // Testing + with(Dependencies.Testing) { + testImplementation(junit) + androidTestImplementation(junitAndroidX) + androidTestImplementation(espresso) + } +} + +repositories { + mavenCentral() +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index b1f6206..ece3127 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 6c849af..0000000 --- a/build.gradle +++ /dev/null @@ -1,37 +0,0 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - -buildscript { - ext.kotlin_version = '1.5.10' - ext.hilt_version = '2.35.1' - ext.room_version = '2.3.0' - ext.work_version ='2.5.0' - ext.hiltx_version = '1.0.0' - ext.retrofit_version = '2.9.0' - ext.markwon_version = '4.6.2' - - repositories { - google() - jcenter() - maven { url 'https://jitpack.io' } - } - dependencies { - classpath 'com.android.tools.build:gradle:4.2.2' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version" - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - } -} - -allprojects { - repositories { - google() - jcenter() - maven { url 'https://jitpack.io' } - } -} - -task clean(type: Delete) { - delete rootProject.buildDir -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..0f05a66 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,31 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + repositories { + google() + jcenter() + maven("https://jitpack.io") + } + dependencies { + with(Dependencies.GradlePlugins) { + classpath(gradle) + classpath(hiltAndroid) + classpath(kotlin) + } + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + google() + jcenter() + maven("https://jitpack.io") + } +} + +tasks.register("clean", Delete::class) { + delete(rootProject.buildDir) +} diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..445e21f --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,7 @@ +repositories { + jcenter() +} + +plugins { + `kotlin-dsl` +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/AppConfig.kt b/buildSrc/src/main/kotlin/AppConfig.kt new file mode 100644 index 0000000..0145abb --- /dev/null +++ b/buildSrc/src/main/kotlin/AppConfig.kt @@ -0,0 +1,9 @@ +object AppConfig { + const val compileSdkVersion = 30 + const val targetSdkVersion = compileSdkVersion + const val minSdkVersion = 21 + const val ndkVersion = "21.3.6528147" + + const val versionCode = 17 + const val versionName = "Beta 1.5.2" +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt new file mode 100644 index 0000000..5514477 --- /dev/null +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -0,0 +1,75 @@ +object Dependencies { + private object Versions { + const val Kotlin = "1.5.10" + const val HiltX = "1.0.0" + const val Hilt = "2.35.1" + const val Room = "2.3.0" + const val Work = "2.5.0" + const val Markwon = "4.6.2" + const val Retrofit = "2.9.0" + } + + object GradlePlugins { + const val gradle = "com.android.tools.build:gradle:4.2.2" + const val hiltAndroid = "com.google.dagger:hilt-android-gradle-plugin:${Versions.Hilt}" + const val kotlin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.Kotlin}" + } + + object Kotlin { + const val kotlinStdlib = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Versions.Kotlin}" + } + + object AndroidX { + const val activity = "androidx.activity:activity-ktx:1.2.3" + const val appCompat = "androidx.appcompat:appcompat:1.3.0" + const val cardView = "androidx.cardview:cardview:1.0.0" + const val constraintLayout = "androidx.constraintlayout:constraintlayout:2.0.4" + const val core = "androidx.core:core-ktx:1.6.0" + const val documentFile = "androidx.documentfile:documentfile:1.0.1" + const val fragment = "androidx.fragment:fragment-ktx:1.3.5" + const val hiltWork = "androidx.hilt:hilt-work:${Versions.HiltX}" + const val lifecycleExtensions = "androidx.lifecycle:lifecycle-extensions:2.2.0" + const val lifecycleViewModel = "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1" + const val preference = "androidx.preference:preference-ktx:1.1.1" + const val recyclerView = "androidx.recyclerview:recyclerview:1.2.1" + const val room = "androidx.room:room-runtime:${Versions.Room}" + const val roomRxJava = "androidx.room:room-rxjava2:${Versions.Room}" + const val swipeRefreshLayout = "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0" + const val work = "androidx.work:work-runtime-ktx:${Versions.Work}" + const val workRxJava = "androidx.work:work-rxjava2:${Versions.Work}" + const val material = "com.google.android.material:material:1.4.0" + } + + object ThirdParty { + const val masterSwitchPreference = "com.github.svenoaks:MasterSwitchPreference:0.9.1" + const val flexbox = "com.google.android:flexbox:2.0.1" + const val gson = "com.google.code.gson:gson:2.8.6" + const val hilt = "com.google.dagger:hilt-android:${Versions.Hilt}" + const val picasso = "com.squareup.picasso:picasso:2.71828" + const val markwon = "io.noties.markwon:core:${Versions.Markwon}" + const val markwonImagePicasso = "io.noties.markwon:image-picasso:${Versions.Markwon}" + const val markwonLinkify = "io.noties.markwon:linkify:${Versions.Markwon}" + const val rxJava = "io.reactivex.rxjava2:rxjava:2.2.10" + const val rxJavaAndroid = "io.reactivex.rxjava2:rxandroid:2.1.1" + const val commonsCompress = "org.apache.commons:commons-compress:1.21" + const val xz = "org.tukaani:xz:1.9" + } + + object GitHub { + const val retrofit = "com.squareup.retrofit2:adapter-rxjava2:${Versions.Retrofit}" + const val retrofitAdapterRxJava = "com.squareup.retrofit2:adapter-rxjava2:${Versions.Retrofit}" + const val retrofitConverterGson = "com.squareup.retrofit2:converter-gson:${Versions.Retrofit}" + } + + object Kapt { + const val hiltCompiler = "androidx.hilt:hilt-compiler:${Versions.HiltX}" + const val hiltCompilerAndroid = "com.google.dagger:hilt-android-compiler:${Versions.Hilt}" + const val roomCompiler = "androidx.room:room-compiler:${Versions.Room}" + } + + object Testing { + const val junit = "junit:junit:4.12" + const val junitAndroidX = "androidx.test.ext:junit:1.1.1" + const val espresso = "androidx.test.espresso:espresso-core:3.1.0" + } +} \ No newline at end of file