From 7cf869392384c02d14c0735e49eb1852df995e2c Mon Sep 17 00:00:00 2001 From: Simona Stojanovic Date: Fri, 13 May 2022 15:46:20 +0100 Subject: [PATCH] Add common build convention for feature modules Change-Id: I24d54343de2835fff4f7a8dfc598b9a1864ffec7 --- .../nowinandroid.android.feature.gradle.kts | 59 +++++++++++++++++++ .../nowinandroid.android.library.gradle.kts | 13 ++++ core-data-test/build.gradle.kts | 7 --- core-database/build.gradle.kts | 9 --- core-datastore-test/build.gradle.kts | 7 --- core-testing/build.gradle.kts | 7 --- feature-author/build.gradle.kts | 40 +------------ feature-foryou/build.gradle.kts | 39 +----------- feature-interests/build.gradle.kts | 42 +------------ feature-topic/build.gradle.kts | 40 +------------ sync/build.gradle.kts | 7 --- 11 files changed, 76 insertions(+), 194 deletions(-) create mode 100644 build-logic/convention/src/main/kotlin/nowinandroid.android.feature.gradle.kts diff --git a/build-logic/convention/src/main/kotlin/nowinandroid.android.feature.gradle.kts b/build-logic/convention/src/main/kotlin/nowinandroid.android.feature.gradle.kts new file mode 100644 index 000000000..fdd9b4a90 --- /dev/null +++ b/build-logic/convention/src/main/kotlin/nowinandroid.android.feature.gradle.kts @@ -0,0 +1,59 @@ +/* + * Copyright 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import com.google.samples.apps.nowinandroid.configureKotlinAndroid +import org.gradle.kotlin.dsl.support.delegates.ProjectDelegate + +plugins { + id("com.android.library") + kotlin("android") + kotlin("kapt") +} + +android { + defaultConfig { + testInstrumentationRunner = + "com.google.samples.apps.nowinandroid.core.testing.NiaTestRunner" + } +} + +val libs = extensions.getByType().named("libs") + +dependencies { + implementation(project(":core-model")) + implementation(project(":core-ui")) + implementation(project(":core-data")) + implementation(project(":core-common")) + implementation(project(":core-navigation")) + + testImplementation(project(":core-testing")) + androidTestImplementation(project(":core-testing")) + + add("implementation", libs.findLibrary("coil.kt").get()) + add("implementation", libs.findLibrary("coil.kt.compose").get()) + + add("implementation", libs.findLibrary("androidx.hilt.navigation.compose").get()) + add("implementation", libs.findLibrary("androidx.lifecycle.viewModelCompose").get()) + + add("implementation", libs.findLibrary("kotlinx.coroutines.android").get()) + + add("implementation", libs.findLibrary("hilt.android").get()) + add("kapt", libs.findLibrary("hilt.compiler").get()) + + // TODO : Remove this dependency once we upgrade to Android Studio Dolphin b/228889042 + // These dependencies are currently necessary to render Compose previews + add("debugImplementation", libs.findLibrary("androidx.customview.poolingcontainer").get()) +} diff --git a/build-logic/convention/src/main/kotlin/nowinandroid.android.library.gradle.kts b/build-logic/convention/src/main/kotlin/nowinandroid.android.library.gradle.kts index c6381943d..2ddc4b01a 100644 --- a/build-logic/convention/src/main/kotlin/nowinandroid.android.library.gradle.kts +++ b/build-logic/convention/src/main/kotlin/nowinandroid.android.library.gradle.kts @@ -28,3 +28,16 @@ android { targetSdk = 32 } } + +val libs = extensions.getByType().named("libs") + +dependencies { + // androidx.test is forcing JUnit, 4.12. This forces it to use 4.13 + configurations.configureEach { + resolutionStrategy { + force(libs.findLibrary("junit4").get()) + // Temporary workaround for https://issuetracker.google.com/174733673 + force("org.objenesis:objenesis:2.6") + } + } +} diff --git a/core-data-test/build.gradle.kts b/core-data-test/build.gradle.kts index 24ec632fd..df4796506 100644 --- a/core-data-test/build.gradle.kts +++ b/core-data-test/build.gradle.kts @@ -27,11 +27,4 @@ dependencies { implementation(libs.hilt.android) kapt(libs.hilt.compiler) kaptAndroidTest(libs.hilt.compiler) - - configurations.configureEach { - resolutionStrategy { - // Temporary workaround for https://issuetracker.google.com/174733673 - force("org.objenesis:objenesis:2.6") - } - } } diff --git a/core-database/build.gradle.kts b/core-database/build.gradle.kts index 0461f28f2..5abe343b9 100644 --- a/core-database/build.gradle.kts +++ b/core-database/build.gradle.kts @@ -49,13 +49,4 @@ dependencies { kapt(libs.hilt.compiler) androidTestImplementation(project(":core-testing")) - - // androidx.test is forcing JUnit, 4.12. This forces it to use 4.13 - configurations.configureEach { - resolutionStrategy { - force(libs.junit4) - // Temporary workaround for https://issuetracker.google.com/174733673 - force("org.objenesis:objenesis:2.6") - } - } } \ No newline at end of file diff --git a/core-datastore-test/build.gradle.kts b/core-datastore-test/build.gradle.kts index 9b59bd85b..068586022 100644 --- a/core-datastore-test/build.gradle.kts +++ b/core-datastore-test/build.gradle.kts @@ -29,11 +29,4 @@ dependencies { implementation(libs.hilt.android) kapt(libs.hilt.compiler) kaptAndroidTest(libs.hilt.compiler) - - configurations.configureEach { - resolutionStrategy { - // Temporary workaround for https://issuetracker.google.com/174733673 - force("org.objenesis:objenesis:2.6") - } - } } diff --git a/core-testing/build.gradle.kts b/core-testing/build.gradle.kts index 795da59d8..471700ccc 100644 --- a/core-testing/build.gradle.kts +++ b/core-testing/build.gradle.kts @@ -39,11 +39,4 @@ dependencies { api(libs.hilt.android.testing) debugApi(libs.androidx.compose.ui.testManifest) - - configurations.configureEach { - resolutionStrategy { - // Temporary workaround for https://issuetracker.google.com/174733673 - force("org.objenesis:objenesis:2.6") - } - } } diff --git a/feature-author/build.gradle.kts b/feature-author/build.gradle.kts index d212fe597..9316decc6 100644 --- a/feature-author/build.gradle.kts +++ b/feature-author/build.gradle.kts @@ -15,51 +15,13 @@ */ plugins { id("nowinandroid.android.library") + id("nowinandroid.android.feature") id("nowinandroid.android.library.compose") id("nowinandroid.android.library.jacoco") - kotlin("kapt") id("dagger.hilt.android.plugin") id("nowinandroid.spotless") } -android { - defaultConfig { - testInstrumentationRunner = "com.google.samples.apps.nowinandroid.core.testing.NiaTestRunner" - } -} - dependencies { - implementation(project(":core-model")) - implementation(project(":core-ui")) - implementation(project(":core-data")) - implementation(project(":core-common")) - implementation(project(":core-navigation")) - - testImplementation(project(":core-testing")) - androidTestImplementation(project(":core-testing")) - - implementation(libs.coil.kt) - implementation(libs.coil.kt.compose) - - implementation(libs.kotlinx.coroutines.android) implementation(libs.kotlinx.datetime) - - implementation(libs.androidx.hilt.navigation.compose) - implementation(libs.androidx.lifecycle.viewModelCompose) - - implementation(libs.hilt.android) - kapt(libs.hilt.compiler) - - // TODO : Remove this dependency once we upgrade to Android Studio Dolphin b/228889042 - // These dependencies are currently necessary to render Compose previews - debugImplementation(libs.androidx.customview.poolingcontainer) - - // androidx.test is forcing JUnit, 4.12. This forces it to use 4.13 - configurations.configureEach { - resolutionStrategy { - force(libs.junit4) - // Temporary workaround for https://issuetracker.google.com/174733673 - force("org.objenesis:objenesis:2.6") - } - } } diff --git a/feature-foryou/build.gradle.kts b/feature-foryou/build.gradle.kts index eb8cea8f1..5303a2782 100644 --- a/feature-foryou/build.gradle.kts +++ b/feature-foryou/build.gradle.kts @@ -15,54 +15,17 @@ */ plugins { id("nowinandroid.android.library") + id("nowinandroid.android.feature") id("nowinandroid.android.library.compose") id("nowinandroid.android.library.jacoco") - kotlin("kapt") id("dagger.hilt.android.plugin") id("nowinandroid.spotless") } -android { - defaultConfig { - testInstrumentationRunner = - "com.google.samples.apps.nowinandroid.core.testing.NiaTestRunner" - } -} - dependencies { - implementation(project(":core-model")) - implementation(project(":core-ui")) - implementation(project(":core-data")) - implementation(project(":core-navigation")) - - testImplementation(project(":core-testing")) - androidTestImplementation(project(":core-testing")) - - implementation(libs.kotlinx.coroutines.android) implementation(libs.kotlinx.datetime) implementation(libs.androidx.compose.material3.windowSizeClass) - implementation(libs.androidx.hilt.navigation.compose) - implementation(libs.androidx.lifecycle.viewModelCompose) implementation(libs.accompanist.flowlayout) - - implementation(libs.coil.kt) - implementation(libs.coil.kt.compose) - - implementation(libs.hilt.android) - kapt(libs.hilt.compiler) - - // TODO : Remove this dependency once we upgrade to Android Studio Dolphin b/228889042 - // These dependencies are currently necessary to render Compose previews - debugImplementation(libs.androidx.customview.poolingcontainer) - - // androidx.test is forcing JUnit, 4.12. This forces it to use 4.13 - configurations.configureEach { - resolutionStrategy { - force(libs.junit4) - // Temporary workaround for https://issuetracker.google.com/174733673 - force("org.objenesis:objenesis:2.6") - } - } } diff --git a/feature-interests/build.gradle.kts b/feature-interests/build.gradle.kts index 396d6c85e..15d07ceb7 100644 --- a/feature-interests/build.gradle.kts +++ b/feature-interests/build.gradle.kts @@ -15,49 +15,9 @@ */ plugins { id("nowinandroid.android.library") + id("nowinandroid.android.feature") id("nowinandroid.android.library.compose") id("nowinandroid.android.library.jacoco") - kotlin("kapt") id("dagger.hilt.android.plugin") id("nowinandroid.spotless") } - -android { - defaultConfig { - testInstrumentationRunner = "com.google.samples.apps.nowinandroid.core.testing.NiaTestRunner" - } -} - -dependencies { - implementation(project(":core-model")) - implementation(project(":core-ui")) - implementation(project(":core-data")) - implementation(project(":core-navigation")) - - testImplementation(project(":core-testing")) - androidTestImplementation(project(":core-testing")) - - implementation(libs.coil.kt) - implementation(libs.coil.kt.compose) - - implementation(libs.kotlinx.coroutines.android) - - implementation(libs.androidx.hilt.navigation.compose) - implementation(libs.androidx.lifecycle.viewModelCompose) - - implementation(libs.hilt.android) - kapt(libs.hilt.compiler) - - // TODO : Remove this dependency once we upgrade to Android Studio Dolphin b/228889042 - // These dependencies are currently necessary to render Compose previews - debugImplementation(libs.androidx.customview.poolingcontainer) - - // androidx.test is forcing JUnit, 4.12. This forces it to use 4.13 - configurations.configureEach { - resolutionStrategy { - force(libs.junit4) - // Temporary workaround for https://issuetracker.google.com/174733673 - force("org.objenesis:objenesis:2.6") - } - } -} diff --git a/feature-topic/build.gradle.kts b/feature-topic/build.gradle.kts index de2c8085b..9316decc6 100644 --- a/feature-topic/build.gradle.kts +++ b/feature-topic/build.gradle.kts @@ -15,51 +15,13 @@ */ plugins { id("nowinandroid.android.library") + id("nowinandroid.android.feature") id("nowinandroid.android.library.compose") id("nowinandroid.android.library.jacoco") - kotlin("kapt") id("dagger.hilt.android.plugin") id("nowinandroid.spotless") } -android { - defaultConfig { - testInstrumentationRunner = "com.google.samples.apps.nowinandroid.core.testing.NiaTestRunner" - } -} - dependencies { - implementation(project(":core-model")) - implementation(project(":core-ui")) - implementation(project(":core-data")) - implementation(project(":core-common")) - implementation(project(":core-navigation")) - - testImplementation(project(":core-testing")) - androidTestImplementation(project(":core-testing")) - - implementation(libs.kotlinx.coroutines.android) implementation(libs.kotlinx.datetime) - - implementation(libs.androidx.hilt.navigation.compose) - implementation(libs.androidx.lifecycle.viewModelCompose) - - implementation(libs.coil.kt) - implementation(libs.coil.kt.compose) - - implementation(libs.hilt.android) - kapt(libs.hilt.compiler) - - // TODO : Remove this dependency once we upgrade to Android Studio Dolphin b/228889042 - // These dependencies are currently necessary to render Compose previews - debugImplementation(libs.androidx.customview.poolingcontainer) - - // androidx.test is forcing JUnit, 4.12. This forces it to use 4.13 - configurations.configureEach { - resolutionStrategy { - force(libs.junit4) - // Temporary workaround for https://issuetracker.google.com/174733673 - force("org.objenesis:objenesis:2.6") - } - } } diff --git a/sync/build.gradle.kts b/sync/build.gradle.kts index 531032a9f..66b762118 100644 --- a/sync/build.gradle.kts +++ b/sync/build.gradle.kts @@ -50,11 +50,4 @@ dependencies { kaptAndroidTest(libs.hilt.compiler) kaptAndroidTest(libs.hilt.ext.compiler) - - configurations.configureEach { - resolutionStrategy { - // Temporary workaround for https://issuetracker.google.com/174733673 - force("org.objenesis:objenesis:2.6") - } - } }