From 9243c7b6afc9d856837ccd477b4e08a7331a49d5 Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Sat, 27 Apr 2024 14:54:21 +0300 Subject: [PATCH] Gradle scripts were migrated to ".gradle.kts", version catalogs were added, libraries dependencies were updated. --- app/build.gradle | 63 ------------- app/build.gradle.kts | 89 +++++++++++++++++++ app/proguard-rules.pro | 2 +- .../architecture/blueprints/todoapp/Event.kt | 4 +- .../todoapp/tasks/TasksViewModel.kt | 2 +- build.gradle | 51 ----------- build.gradle.kts | 7 ++ gradle/libs.versions.toml | 61 +++++++++++++ gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle | 1 - settings.gradle.kts | 16 ++++ 11 files changed, 178 insertions(+), 120 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 gradle/libs.versions.toml delete mode 100644 settings.gradle create mode 100644 settings.gradle.kts diff --git a/app/build.gradle b/app/build.gradle deleted file mode 100644 index edea69366..000000000 --- a/app/build.gradle +++ /dev/null @@ -1,63 +0,0 @@ -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: 'kotlin-kapt' -apply plugin: "androidx.navigation.safeargs.kotlin" - -android { - compileSdkVersion rootProject.compileSdkVersion - - defaultConfig { - applicationId "com.example.android.architecture.blueprints.reactive" - minSdkVersion rootProject.minSdkVersion - targetSdkVersion rootProject.targetSdkVersion - versionCode 1 - versionName "1.0" - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - - dataBinding { - enabled = true - enabledForTests = true - } -} - -dependencies { - - // App dependencies - implementation "androidx.appcompat:appcompat:$appCompatVersion" - implementation "androidx.swiperefreshlayout:swiperefreshlayout:$swipeRefreshLayoutVersion" - implementation "com.google.android.material:material:$materialVersion" - implementation "androidx.recyclerview:recyclerview:$recyclerViewVersion" - implementation "androidx.annotation:annotation:$androidXAnnotations" - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion" - implementation "com.jakewharton.timber:timber:$timberVersion" - - // Architecture Components - implementation "androidx.room:room-runtime:$roomVersion" - kapt "androidx.room:room-compiler:$roomVersion" - implementation "androidx.room:room-ktx:$roomVersion" - implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$archLifecycleVersion" - implementation "androidx.lifecycle:lifecycle-livedata-ktx:$archLifecycleVersion" - kapt "androidx.lifecycle:lifecycle-compiler:$archLifecycleVersion" - implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$archLifecycleVersion" - implementation "androidx.lifecycle:lifecycle-livedata-ktx:$archLifecycleVersion" - implementation "androidx.navigation:navigation-fragment-ktx:$navigationVersion" - implementation "androidx.navigation:navigation-ui-ktx:$navigationVersion" - - // Dependencies for local unit tests - testImplementation "junit:junit:$junitVersion" - - // AndroidX Test - Instrumented testing - androidTestImplementation "androidx.test.ext:junit:$androidXTestExtKotlinRunnerVersion" - androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion" - - // Kotlin - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion" - implementation "androidx.fragment:fragment-ktx:$fragmentKtxVersion" -} diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 000000000..009a9cbfe --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,89 @@ +plugins { + alias(libs.plugins.androidApplication) + alias(libs.plugins.kotlinAndroid) + alias(libs.plugins.googleKsp) + alias(libs.plugins.kotlinKapt) + alias(libs.plugins.androidxSafeargs) +} + +android { + compileSdk = libs.versions.compileSdkVersion.get().toInt() + + namespace = "com.example.android.architecture.blueprints.todoapp" + + defaultConfig { + applicationId = "com.example.android.architecture.blueprints.reactive" + minSdk = libs.versions.minSdkVersion.get().toInt() + targetSdk = libs.versions.targetSdkVersion.get().toInt() + versionCode = 1 + versionName = "1.0" + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildFeatures { + buildConfig = true + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles.addAll( + listOf( + getDefaultProguardFile("proguard-android-optimize.txt"), + file("proguard-rules.pro") + ) + ) + } + } + + dataBinding { + enable = true + enableForTests = true + } + + val javaVersion = JavaVersion.toVersion(libs.versions.javaVersion.get()) + + compileOptions { + sourceCompatibility = javaVersion + targetCompatibility = javaVersion + } + + kotlinOptions { + jvmTarget = javaVersion.toString() + } +} + +dependencies { + + // App dependencies + implementation(libs.androidx.appcompat) + implementation(libs.androidx.swiperefreshlayout) + implementation(libs.material) + implementation(libs.androidx.recyclerview) + implementation(libs.androidx.annotations) + implementation(libs.kotlinx.coroutines.android) + implementation(libs.timber) + + // Architecture Components + implementation(libs.androidx.room.runtime) + ksp(libs.androidx.room.compiler) + implementation(libs.androidx.room.ktx) + implementation(libs.androidx.lifecycle.viewmodel.ktx) + implementation(libs.androidx.lifecycle.livedata.ktx) + implementation(libs.androidx.lifecycle.commonJava8) + implementation(libs.androidx.lifecycle.viewmodel.ktx) + implementation(libs.androidx.lifecycle.livedata.ktx) + implementation(libs.androidx.navigation.fragment.ktx) + implementation(libs.androidx.navigation.ui.ktx) + + // Dependencies for local unit tests + testImplementation(libs.junit) + + // AndroidX Test - Instrumented testing + androidTestImplementation(libs.androidx.junit) + androidTestImplementation(libs.androidx.espresso.core) + + // Kotlin + implementation(libs.kotlin.stdlib) + implementation(libs.androidx.fragment.ktx) +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index f1b424510..2f9dc5a47 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/app/src/main/java/com/example/android/architecture/blueprints/todoapp/Event.kt b/app/src/main/java/com/example/android/architecture/blueprints/todoapp/Event.kt index 77c6b4369..8ab3689a5 100644 --- a/app/src/main/java/com/example/android/architecture/blueprints/todoapp/Event.kt +++ b/app/src/main/java/com/example/android/architecture/blueprints/todoapp/Event.kt @@ -51,8 +51,8 @@ open class Event(private val content: T) { * [onEventUnhandledContent] is *only* called if the [Event]'s contents has not been handled. */ class EventObserver(private val onEventUnhandledContent: (T) -> Unit) : Observer> { - override fun onChanged(event: Event?) { - event?.getContentIfNotHandled()?.let { + override fun onChanged(event: Event) { + event.getContentIfNotHandled()?.let { onEventUnhandledContent(it) } } diff --git a/app/src/main/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksViewModel.kt b/app/src/main/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksViewModel.kt index 8cc67bb53..25dd80130 100644 --- a/app/src/main/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksViewModel.kt +++ b/app/src/main/java/com/example/android/architecture/blueprints/todoapp/tasks/TasksViewModel.kt @@ -85,7 +85,7 @@ class TasksViewModel(application: Application) : AndroidViewModel(application) { private var resultMessageShown: Boolean = false // This LiveData depends on another so we can use a transformation. - val empty: LiveData = Transformations.map(_items) { + val empty: LiveData = _items.map { it.isEmpty() } diff --git a/build.gradle b/build.gradle deleted file mode 100644 index c851a4380..000000000 --- a/build.gradle +++ /dev/null @@ -1,51 +0,0 @@ -buildscript { - ext.kotlinVersion = '1.5.31' - ext.navigationVersion = '2.3.5' - repositories { - google() - mavenCentral() - } - dependencies { - classpath 'com.android.tools.build:gradle:7.0.3' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" - classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigationVersion" - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - } -} - -allprojects { - repositories { - google() - mavenCentral() - } -} - -// Define versions in a single place -ext { - // Sdk and tools - minSdkVersion = 21 - targetSdkVersion = 31 - compileSdkVersion = 31 - - // App dependencies - androidXVersion = '1.0.0' - androidXTestCoreVersion = '1.3.0' - androidXTestExtKotlinRunnerVersion = '1.1.3' - androidXTestRulesVersion = '1.2.0' - androidXAnnotations = '1.3.0' - appCompatVersion = '1.4.0' - archLifecycleVersion = '2.4.0' - coroutinesVersion = '1.5.2' - cardVersion = '1.0.0' - espressoVersion = '3.4.0' - fragmentKtxVersion = '1.4.0' - junitVersion = '4.13.2' - materialVersion = '1.4.0' - recyclerViewVersion = '1.2.1' - roomVersion = '2.3.0' - rulesVersion = '1.0.1' - swipeRefreshLayoutVersion = '1.1.0' - timberVersion = '4.7.1' -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 000000000..9caa7d1e1 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,7 @@ +plugins { + alias(libs.plugins.androidApplication).apply(false) + alias(libs.plugins.kotlinAndroid).apply(false) + alias(libs.plugins.googleKsp).apply(false) + alias(libs.plugins.kotlinKapt).apply(false) + alias(libs.plugins.androidxSafeargs).apply(false) +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 000000000..973273f0c --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,61 @@ +[versions] + +minSdkVersion = "21" +targetSdkVersion = "34" +compileSdkVersion = "34" + +agpVersion = "8.2.2" +javaVersion = "1.8" +kotlinVersion = "1.9.23" +kspVersion = "1.9.23-1.0.20" +navigationVersion = "2.7.7" + +androidXVersion = "1.0.0" +androidXTestCoreVersion = "1.3.0" +androidXTestExtKotlinRunnerVersion = "1.1.5" +androidXTestRulesVersion = "1.2.0" +androidXAnnotations = "1.7.1" +appCompatVersion = "1.6.1" +archLifecycleVersion = "2.7.0" +coroutinesVersion = "1.8.0" +cardVersion = "1.0.0" +espressoVersion = "3.5.1" +fragmentKtxVersion = "1.6.2" +junitVersion = "4.13.2" +materialVersion = "1.11.0" +recyclerViewVersion = "1.3.2" +roomVersion = "2.6.1" +rulesVersion = "1.0.1" +swipeRefreshLayoutVersion = "1.1.0" +timberVersion = "5.0.1" + +[libraries] + +androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appCompatVersion" } +androidx-annotations = { module = "androidx.annotation:annotation", version.ref = "androidXAnnotations" } +androidx-espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "espressoVersion" } +androidx-fragment-ktx = { module = "androidx.fragment:fragment-ktx", version.ref = "fragmentKtxVersion" } +androidx-junit = { module = "androidx.test.ext:junit", version.ref = "androidXTestExtKotlinRunnerVersion" } +androidx-lifecycle-commonJava8 = { module = "androidx.lifecycle:lifecycle-common-java8", version.ref = "archLifecycleVersion" } +androidx-lifecycle-livedata-ktx = { module = "androidx.lifecycle:lifecycle-livedata-ktx", version.ref = "archLifecycleVersion" } +androidx-lifecycle-viewmodel-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "archLifecycleVersion" } +androidx-navigation-fragment-ktx = { module = "androidx.navigation:navigation-fragment-ktx", version.ref = "navigationVersion" } +androidx-navigation-ui-ktx = { module = "androidx.navigation:navigation-ui-ktx", version.ref = "navigationVersion" } +androidx-recyclerview = { module = "androidx.recyclerview:recyclerview", version.ref = "recyclerViewVersion" } +androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "roomVersion" } +androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "roomVersion" } +androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "roomVersion" } +androidx-swiperefreshlayout = { module = "androidx.swiperefreshlayout:swiperefreshlayout", version.ref = "swipeRefreshLayoutVersion" } +junit = { module = "junit:junit", version.ref = "junitVersion" } +kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlinVersion" } +kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "coroutinesVersion" } +material = { module = "com.google.android.material:material", version.ref = "materialVersion" } +timber = { module = "com.jakewharton.timber:timber", version.ref = "timberVersion" } + +[plugins] + +androidApplication = { id = "com.android.application", version.ref = "agpVersion" } +androidxSafeargs = { id = "androidx.navigation.safeargs.kotlin", version.ref = "navigationVersion" } +kotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlinVersion" } +kotlinKapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlinVersion" } +googleKsp = { id = "com.google.devtools.ksp", version.ref = "kspVersion" } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e228a385f..7b052a2dc 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Mon Jun 14 12:47:31 UTC 2021 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index e7b4def49..000000000 --- a/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -include ':app' diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 000000000..9b93bf90d --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,16 @@ +pluginManagement { + repositories { + google() + mavenCentral() + } +} + +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } +} + +include(":app") \ No newline at end of file