diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md index da9b19682..c38247d23 100644 --- a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md +++ b/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md @@ -6,7 +6,7 @@ label: 'triage me' Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open a GitHub issue as a bug/feature request before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea -- [ ] Ensure the tests and linter pass (`./gradlew spotlessApply` to automatically apply formatting) +- [ ] Ensure the tests and linter pass (`./gradlew --init-script gradle/init.gradle.kts spotlessApply` to automatically apply formatting) - [ ] Appropriate docs were updated (if necessary) Is this your first Pull Request? diff --git a/.github/workflows/Build.yaml b/.github/workflows/Build.yaml index de2666fa1..e19caebef 100644 --- a/.github/workflows/Build.yaml +++ b/.github/workflows/Build.yaml @@ -34,10 +34,10 @@ jobs: uses: gradle/gradle-build-action@v2 - name: Check spotless - run: ./gradlew spotlessCheck --stacktrace + run: ./gradlew spotlessCheck --init-script gradle/init.gradle.kts --no-configuration-cache --stacktrace - name: Check lint - run: ./gradlew lintDebug --stacktrace + run: ./gradlew lintDemoDebug --stacktrace - name: Build all build type and flavor permutations run: ./gradlew assemble --stacktrace diff --git a/app-nia-catalog/build.gradle.kts b/app-nia-catalog/build.gradle.kts index 88b105542..33ce4dc24 100644 --- a/app-nia-catalog/build.gradle.kts +++ b/app-nia-catalog/build.gradle.kts @@ -16,7 +16,6 @@ plugins { id("nowinandroid.android.application") id("nowinandroid.android.application.compose") - id("nowinandroid.spotless") } android { diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 690cd172f..2f25807ba 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -20,10 +20,8 @@ plugins { id("nowinandroid.android.application") id("nowinandroid.android.application.compose") id("nowinandroid.android.application.jacoco") - kotlin("kapt") + id("nowinandroid.android.hilt") id("jacoco") - id("dagger.hilt.android.plugin") - id("nowinandroid.spotless") id("nowinandroid.firebase-perf") } @@ -67,19 +65,6 @@ android { } } - // @see Flavor for more details on the app product flavors. - flavorDimensions += FlavorDimension.contentType.name - productFlavors { - Flavor.values().forEach { - create(it.name) { - dimension = it.dimension.name - if (it.applicationIdSuffix != null) { - applicationIdSuffix = it.applicationIdSuffix - } - } - } - } - packagingOptions { resources { excludes.add("/META-INF/{AL2.0,LGPL2.1}") @@ -124,17 +109,13 @@ dependencies { implementation(libs.coil.kt) implementation(libs.coil.kt.svg) +} - implementation(libs.hilt.android) - kapt(libs.hilt.compiler) - kaptAndroidTest(libs.hilt.compiler) - - // 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") - } +// 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/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/NavigationTest.kt b/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/NavigationTest.kt index 90d5d92dc..184d48507 100644 --- a/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/NavigationTest.kt +++ b/app/src/androidTest/java/com/google/samples/apps/nowinandroid/ui/NavigationTest.kt @@ -25,7 +25,8 @@ import androidx.compose.ui.test.performClick import androidx.test.espresso.Espresso import androidx.test.espresso.NoActivityResumedException import com.google.samples.apps.nowinandroid.MainActivity -import com.google.samples.apps.nowinandroid.R +import com.google.samples.apps.nowinandroid.feature.foryou.R as FeatureForyouR +import com.google.samples.apps.nowinandroid.feature.interests.R as FeatureInterestsR import dagger.hilt.android.testing.BindValue import dagger.hilt.android.testing.HiltAndroidRule import dagger.hilt.android.testing.HiltAndroidTest @@ -70,11 +71,11 @@ class NavigationTest { @Before fun setup() { composeTestRule.activity.apply { - done = getString(R.string.done) - navigateUp = getString(R.string.navigate_up) - forYouLoading = getString(R.string.for_you_loading) - forYou = getString(R.string.for_you) - interests = getString(R.string.interests) + done = getString(FeatureForyouR.string.done) + navigateUp = getString(FeatureForyouR.string.navigate_up) + forYouLoading = getString(FeatureForyouR.string.for_you_loading) + forYou = getString(FeatureForyouR.string.for_you) + interests = getString(FeatureInterestsR.string.interests) sampleTopic = "Headlines" } } diff --git a/benchmark/build.gradle.kts b/benchmark/build.gradle.kts index fab2055e7..e39e716f2 100644 --- a/benchmark/build.gradle.kts +++ b/benchmark/build.gradle.kts @@ -19,7 +19,6 @@ import com.google.samples.apps.nowinandroid.configureFlavors plugins { id("nowinandroid.android.test") - id("nowinandroid.spotless") } android { @@ -30,6 +29,10 @@ android { testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } + buildFeatures { + buildConfig = true + } + buildTypes { // This benchmark buildType is used for benchmarking, and should function like your // release build (for example, with minification on). It's signed with a debug key diff --git a/build-logic/README.md b/build-logic/README.md index 093e5d857..0458b4fb1 100644 --- a/build-logic/README.md +++ b/build-logic/README.md @@ -29,8 +29,6 @@ setup. Current list of convention plugins: -- [`nowinandroid.spotless`](convention/src/main/kotlin/SpotlessConventionPlugin.kt): - Configures spotless. - [`nowinandroid.android.application`](convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt), [`nowinandroid.android.library`](convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt), [`nowinandroid.android.test`](convention/src/main/kotlin/AndroidTestConventionPlugin.kt): diff --git a/build-logic/convention/build.gradle.kts b/build-logic/convention/build.gradle.kts index 52dfeafb5..453085807 100644 --- a/build-logic/convention/build.gradle.kts +++ b/build-logic/convention/build.gradle.kts @@ -28,7 +28,6 @@ java { dependencies { compileOnly(libs.android.gradlePlugin) compileOnly(libs.kotlin.gradlePlugin) - compileOnly(libs.spotless.gradlePlugin) } gradlePlugin { @@ -65,9 +64,9 @@ gradlePlugin { id = "nowinandroid.android.test" implementationClass = "AndroidTestConventionPlugin" } - register("spotless") { - id = "nowinandroid.spotless" - implementationClass = "SpotlessConventionPlugin" + register("androidHilt") { + id = "nowinandroid.android.hilt" + implementationClass = "AndroidHiltConventionPlugin" } register("firebase-perf") { id = "nowinandroid.firebase-perf" diff --git a/build-logic/convention/src/main/kotlin/AndroidApplicationComposeConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidApplicationComposeConventionPlugin.kt index ea40d8c25..cf90b17af 100644 --- a/build-logic/convention/src/main/kotlin/AndroidApplicationComposeConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidApplicationComposeConventionPlugin.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -import com.android.build.gradle.internal.dsl.BaseAppModuleExtension +import com.android.build.api.dsl.ApplicationExtension import com.google.samples.apps.nowinandroid.configureAndroidCompose import org.gradle.api.Plugin import org.gradle.api.Project @@ -24,7 +24,7 @@ class AndroidApplicationComposeConventionPlugin : Plugin { override fun apply(target: Project) { with(target) { pluginManager.apply("com.android.application") - val extension = extensions.getByType() + val extension = extensions.getByType() configureAndroidCompose(extension) } } diff --git a/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt index fe7df5c77..612eb6ad4 100644 --- a/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt @@ -14,8 +14,11 @@ * limitations under the License. */ -import com.android.build.gradle.internal.dsl.BaseAppModuleExtension +import com.android.build.api.variant.ApplicationAndroidComponentsExtension +import com.android.build.api.dsl.ApplicationExtension +import com.google.samples.apps.nowinandroid.configureFlavors import com.google.samples.apps.nowinandroid.configureKotlinAndroid +import com.google.samples.apps.nowinandroid.configurePrintApksTask import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.configure @@ -28,9 +31,13 @@ class AndroidApplicationConventionPlugin : Plugin { apply("org.jetbrains.kotlin.android") } - extensions.configure { + extensions.configure { configureKotlinAndroid(this) defaultConfig.targetSdk = 33 + configureFlavors(this) + } + extensions.configure { + configurePrintApksTask(this) } } } diff --git a/build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt index 934a38af1..ec0b0b223 100644 --- a/build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt @@ -26,9 +26,8 @@ class AndroidFeatureConventionPlugin : Plugin { override fun apply(target: Project) { with(target) { pluginManager.apply { - apply("com.android.library") - apply("org.jetbrains.kotlin.android") - apply("org.jetbrains.kotlin.kapt") + apply("nowinandroid.android.library") + apply("nowinandroid.android.hilt") } extensions.configure { defaultConfig { @@ -59,9 +58,6 @@ class AndroidFeatureConventionPlugin : Plugin { 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( diff --git a/build-logic/convention/src/main/kotlin/AndroidHiltConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidHiltConventionPlugin.kt new file mode 100644 index 000000000..0ae7e60e0 --- /dev/null +++ b/build-logic/convention/src/main/kotlin/AndroidHiltConventionPlugin.kt @@ -0,0 +1,44 @@ +/* + * 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.android.build.api.variant.LibraryAndroidComponentsExtension +import com.google.samples.apps.nowinandroid.configureJacoco +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.artifacts.VersionCatalogsExtension +import org.gradle.kotlin.dsl.dependencies +import org.gradle.kotlin.dsl.getByType +import org.gradle.kotlin.dsl.kotlin + +class AndroidHiltConventionPlugin : Plugin { + override fun apply(target: Project) { + with(target) { + with(pluginManager) { + apply("org.jetbrains.kotlin.kapt") + apply("dagger.hilt.android.plugin") + } + + val libs = extensions.getByType().named("libs") + dependencies { + "implementation"(libs.findLibrary("hilt.android").get()) + "kapt"(libs.findLibrary("hilt.compiler").get()) + "kaptAndroidTest"(libs.findLibrary("hilt.compiler").get()) + } + + } + } + +} \ No newline at end of file diff --git a/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt index 66c918492..4bcd039f3 100644 --- a/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt @@ -14,9 +14,12 @@ * limitations under the License. */ +import com.android.build.api.variant.AndroidComponentsExtension +import com.android.build.api.variant.LibraryAndroidComponentsExtension import com.android.build.gradle.LibraryExtension import com.google.samples.apps.nowinandroid.configureFlavors import com.google.samples.apps.nowinandroid.configureKotlinAndroid +import com.google.samples.apps.nowinandroid.configurePrintApksTask import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.artifacts.VersionCatalogsExtension @@ -37,18 +40,17 @@ class AndroidLibraryConventionPlugin : Plugin { defaultConfig.targetSdk = 33 configureFlavors(this) } - + extensions.configure { + configurePrintApksTask(this) + } val libs = extensions.getByType().named("libs") - dependencies { - configurations.configureEach { - resolutionStrategy { - force(libs.findLibrary("junit4").get()) - // Temporary workaround for https://issuetracker.google.com/174733673 - force("org.objenesis:objenesis:2.6") - } + configurations.configureEach { + resolutionStrategy { + force(libs.findLibrary("junit4").get()) + // Temporary workaround for https://issuetracker.google.com/174733673 + force("org.objenesis:objenesis:2.6") } } } } - -} +} \ No newline at end of file diff --git a/build-logic/convention/src/main/kotlin/SpotlessConventionPlugin.kt b/build-logic/convention/src/main/kotlin/SpotlessConventionPlugin.kt deleted file mode 100644 index eaf907ce2..000000000 --- a/build-logic/convention/src/main/kotlin/SpotlessConventionPlugin.kt +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.diffplug.gradle.spotless.SpotlessExtension -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.api.artifacts.VersionCatalogsExtension -import org.gradle.kotlin.dsl.configure -import org.gradle.kotlin.dsl.getByType - -class SpotlessConventionPlugin : Plugin { - override fun apply(target: Project) { - with(target) { - pluginManager.apply("com.diffplug.spotless") - val libs = extensions.getByType().named("libs") - - extensions.configure { - kotlin { - target("**/*.kt") - targetExclude("**/build/**/*.kt") - ktlint(libs.findVersion("ktlint").get().toString()).userData(mapOf("android" to "true")) - licenseHeaderFile(rootProject.file("spotless/copyright.kt")) - } - format("kts") { - target("**/*.kts") - targetExclude("**/build/**/*.kts") - // Look for the first line that doesn't have a block comment (assumed to be the license) - licenseHeaderFile(rootProject.file("spotless/copyright.kts"), "(^(?![\\/ ]\\*).*$)") - } - format("xml") { - target("**/*.xml") - targetExclude("**/build/**/*.xml") - // Look for the first XML tag that isn't a comment (