Skip to content

Commit

Permalink
Merge pull request #1130 from lihenggui/fix/remove_top_level_extension
Browse files Browse the repository at this point in the history
Cherry pick latest updates from NIA
  • Loading branch information
lihenggui authored Jan 3, 2025
2 parents 7212c99 + 4a2f1a3 commit 7de1154
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 57 deletions.
2 changes: 2 additions & 0 deletions .github/ci-gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
org.gradle.daemon=false
org.gradle.parallel=true
org.gradle.workers.max=2
org.gradle.configuration-cache=true
org.gradle.configuration-cache.parallel=true
kotlin.incremental=false
# Controls KotlinOptions.allWarningsAsErrors.
# This value used in CI and is currently set to false.
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/Build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@ jobs:

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}

- name: Accept Android licenses
run: yes | "$ANDROID_HOME"/cmdline-tools/latest/bin/sdkmanager --licenses || true

- name: Check build-logic
run: ./gradlew check -p build-logic
run: ./gradlew :build-logic:convention:check

- name: Check spotless
run: ./gradlew spotlessCheck --init-script gradle/init.gradle.kts --no-configuration-cache
Expand Down Expand Up @@ -292,6 +294,8 @@ jobs:

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}

# Cache AVD. See https://github.com/ReactiveCircus/android-emulator-runner
- name: AVD cache
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/NightlyBaselineProfiles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ jobs:

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}

- name: Setup Android SDK
uses: android-actions/setup-android@v3
Expand All @@ -44,7 +46,7 @@ jobs:
run: yes | sdkmanager --licenses || true

- name: Check build-logic
run: ./gradlew check -p build-logic
run: ./gradlew :build-logic:convention:check

- name: Setup GMD
run: ./gradlew :benchmarks:pixel6Api33Setup
Expand All @@ -57,4 +59,4 @@ jobs:
run: ./gradlew :app:generateReleaseBaselineProfile
-Pandroid.testInstrumentationRunnerArguments.androidx.benchmark.enabledRules=baselineprofile
-Pandroid.testoptions.manageddevices.emulator.gpu="swiftshader_indirect"
--stacktrace
--stacktrace
2 changes: 2 additions & 0 deletions .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ jobs:

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}

- name: Setup Android SDK
uses: android-actions/setup-android@v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ class AndroidFeatureConventionPlugin : Plugin<Project> {
configureGradleManagedDevices(this)
}
dependencies {
add("implementation", project(":core:ui"))
add("implementation", project(":core:designsystem"))
"implementation"(project(":core:ui"))
"implementation"(project(":core:designsystem"))

add("implementation", libs.findLibrary("androidx.hilt.navigation.compose").get())
add("implementation", libs.findLibrary("androidx.lifecycle.runtimeCompose").get())
add("implementation", libs.findLibrary("androidx.lifecycle.viewModelCompose").get())
add("implementation", libs.findLibrary("androidx.navigation.compose").get())
add("implementation", libs.findLibrary("androidx.tracing.ktx").get())
add("implementation", libs.findLibrary("kotlinx.serialization.json").get())
"implementation"(libs.findLibrary("androidx.hilt.navigation.compose").get())
"implementation"(libs.findLibrary("androidx.lifecycle.runtimeCompose").get())
"implementation"(libs.findLibrary("androidx.lifecycle.viewModelCompose").get())
"implementation"(libs.findLibrary("androidx.navigation.compose").get())
"implementation"(libs.findLibrary("androidx.tracing.ktx").get())
"implementation"(libs.findLibrary("kotlinx.serialization.json").get())

add("testImplementation", project(":core:screenshot-testing"))
add("androidTestImplementation", libs.findBundle("androidx.compose.ui.test").get())
"testImplementation"(project(":core:screenshot-testing"))
"androidTestImplementation"(libs.findBundle("androidx.compose.ui.test").get())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ class AndroidLibraryConventionPlugin : Plugin<Project> {
}
}
dependencies {
add("implementation", libs.findLibrary("androidx.tracing.ktx").get())
add("testImplementation", libs.findLibrary("kotlin.test").get())
add("androidTestImplementation", kotlin("test"))
"implementation"(libs.findLibrary("androidx.tracing.ktx").get())
"testImplementation"(libs.findLibrary("kotlin.test").get())
"androidTestImplementation"(libs.findLibrary("kotlin.test").get())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ class AndroidRoomConventionPlugin : Plugin<Project> {
schemaDirectory("$projectDir/schemas")
}
dependencies {
add("implementation", libs.findLibrary("room.runtime").get())
add("implementation", libs.findLibrary("room.ktx").get())
add("ksp", libs.findLibrary("room.compiler").get())
"implementation"(libs.findLibrary("room.runtime").get())
"implementation"(libs.findLibrary("room.ktx").get())
"ksp"(libs.findLibrary("room.compiler").get())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class JvmLibraryConventionPlugin : Plugin<Project> {
}
configureKotlin<KotlinJvmProjectExtension>()
dependencies {
add("testImplementation", libs.findLibrary("kotlin.test").get())
"testImplementation"(libs.findLibrary("kotlin.test").get())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ package com.merxury.blocker

import com.android.build.api.dsl.CommonExtension
import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies
import org.gradle.api.provider.Provider
import org.gradle.kotlin.dsl.assign
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.jetbrains.kotlin.compose.compiler.gradle.ComposeCompilerGradlePluginExtension

/**
* Configure Compose-specific options
*/
Expand All @@ -32,10 +32,10 @@ internal fun Project.configureAndroidCompose(
commonExtension.apply {
dependencies {
val bom = libs.findLibrary("androidx-compose-bom").get()
add("implementation", platform(bom))
add("androidTestImplementation", platform(bom))
add("implementation", libs.findLibrary("androidx-compose-ui-tooling-preview").get())
add("debugImplementation", libs.findLibrary("androidx-compose-ui-tooling").get())
"implementation"(platform(bom))
"androidTestImplementation"(platform(bom))
"implementation"(libs.findLibrary("androidx-compose-ui-tooling-preview").get())
"debugImplementation"(libs.findLibrary("androidx-compose-ui-tooling").get())
}

testOptions {
Expand All @@ -62,7 +62,8 @@ internal fun Project.configureAndroidCompose(
.relativeToRootProject("compose-reports")
.let(reportsDestination::set)

stabilityConfigurationFile =
isolated.rootProject.projectDirectory.file("compose_compiler_config.conf")
stabilityConfigurationFiles.add(
isolated.rootProject.projectDirectory.file("compose_compiler_config.conf"),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,25 @@ enum class FlavorDimension {
@Suppress("EnumEntryName")
enum class BlockerFlavor(val dimension: FlavorDimension, val applicationIdSuffix: String? = null) {
foss(FlavorDimension.contentType),
market(FlavorDimension.contentType)
market(FlavorDimension.contentType),
}

fun configureFlavors(
commonExtension: CommonExtension<*, *, *, *, *, *>,
flavorConfigurationBlock: ProductFlavor.(flavor: BlockerFlavor) -> Unit = {}
flavorConfigurationBlock: ProductFlavor.(flavor: BlockerFlavor) -> Unit = {},
) {
commonExtension.apply {
flavorDimensions += FlavorDimension.contentType.name
FlavorDimension.values().forEach { flavorDimension ->
flavorDimensions += flavorDimension.name
}
productFlavors {
BlockerFlavor.values().forEach {
create(it.name) {
dimension = it.dimension.name
flavorConfigurationBlock(this, it)
BlockerFlavor.values().forEach { blockerFlavor ->
register(blockerFlavor.name) {
dimension = blockerFlavor.dimension.name
flavorConfigurationBlock(this, blockerFlavor)
if (this@apply is ApplicationExtension && this is ApplicationProductFlavor) {
if (it.applicationIdSuffix != null) {
this.applicationIdSuffix = it.applicationIdSuffix
if (blockerFlavor.applicationIdSuffix != null) {
this.applicationIdSuffix = blockerFlavor.applicationIdSuffix
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ package com.merxury.blocker
import com.android.build.api.artifact.ScopedArtifact
import com.android.build.api.variant.AndroidComponentsExtension
import com.android.build.api.variant.ScopedArtifacts
import com.android.build.api.variant.SourceDirectories
import org.gradle.api.Project
import org.gradle.api.file.Directory
import org.gradle.api.file.RegularFile
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.assign
import org.gradle.kotlin.dsl.configure
Expand Down Expand Up @@ -68,37 +70,44 @@ internal fun Project.configureJacoco(
val myObjFactory = project.objects
val buildDir = layout.buildDirectory.get().asFile
val allJars: ListProperty<RegularFile> = myObjFactory.listProperty(RegularFile::class.java)
val allDirectories: ListProperty<Directory> = myObjFactory.listProperty(Directory::class.java)
val allDirectories: ListProperty<Directory> =
myObjFactory.listProperty(Directory::class.java)
val reportTask =
tasks.register("create${variant.name.capitalize()}CombinedCoverageReport", JacocoReport::class) {
tasks.register(
"create${variant.name.capitalize()}CombinedCoverageReport",
JacocoReport::class,
) {

classDirectories.setFrom(
allJars,
allDirectories.map { dirs ->
dirs.map { dir ->
myObjFactory.fileTree().setDir(dir).exclude(coverageExclusions)
}
}
},
)
reports {
xml.required = true
html.required = true
}

// TODO: This is missing files in src/debug/, src/market, src/foss, src/fossDebug...
fun SourceDirectories.Flat?.toFilePaths(): Provider<List<String>> = this
?.all
?.map { directories -> directories.map { it.asFile.path } }
?: provider { emptyList() }
sourceDirectories.setFrom(
files(
"$projectDir/src/main/java",
"$projectDir/src/main/kotlin",
)
variant.sources.java.toFilePaths(),
variant.sources.kotlin.toFilePaths(),
),
)

executionData.setFrom(
project.fileTree("$buildDir/outputs/unit_test_code_coverage/${variant.name}UnitTest")
.matching { include("**/*.exec") },

project.fileTree("$buildDir/outputs/code_coverage/${variant.name}AndroidTest")
.matching { include("**/*.ec") }
.matching { include("**/*.ec") },
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@
package com.merxury.blocker

import com.android.build.api.dsl.CommonExtension
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.kotlin.dsl.assign
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.provideDelegate
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinBaseExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinTopLevelExtension

/**
* Configure base Kotlin with Android options
Expand Down Expand Up @@ -57,7 +54,7 @@ internal fun Project.configureKotlinAndroid(
/**
* Configure base Kotlin options
*/
inline fun <reified T : KotlinTopLevelExtension> Project.configureKotlin() = configure<T> {
inline fun <reified T : KotlinBaseExtension> Project.configureKotlin() = configure<T> {
// Treat all Kotlin warnings as errors (disabled by default)
// Override by setting warningsAsErrors=true in your ~/.gradle/gradle.properties
val warningsAsErrors: String? by project
Expand Down
2 changes: 2 additions & 0 deletions build-logic/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.configureondemand=true
org.gradle.configuration-cache=true
org.gradle.configuration-cache.parallel=true
6 changes: 1 addition & 5 deletions core/designsystem/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ plugins {
}

android {
defaultConfig {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
namespace = "com.merxury.blocker.core.designsystem"
}

Expand All @@ -45,9 +42,8 @@ dependencies {
implementation(libs.material.kolor)

testImplementation(libs.androidx.compose.ui.test)
testImplementation(libs.androidx.compose.ui.testManifest)
testImplementation(libs.hilt.android.testing)
testImplementation(libs.robolectric)
testImplementation(projects.core.screenshotTesting)

androidTestImplementation(libs.bundles.androidx.compose.ui.test)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
* Copyright 2025 Blocker
* 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.
Expand Down Expand Up @@ -43,6 +42,8 @@ import com.merxury.blocker.core.designsystem.theme.LocalTintTheme
import com.merxury.blocker.core.designsystem.theme.TintTheme
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import kotlin.test.assertEquals

/**
Expand All @@ -53,6 +54,7 @@ import kotlin.test.assertEquals
* [LocalBackgroundTheme] — have the expected values for a given theme mode, as specified by the
* design system.
*/
@RunWith(RobolectricTestRunner::class)
class ThemeTest {

@get:Rule
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ org.gradle.configureondemand=false
# Enable caching between builds.
org.gradle.caching=true
# Enable configuration caching between builds.
org.gradle.configuration-cache=false
org.gradle.configuration-cache=true
org.gradle.configuration-cache.parallel=true
# This option is set because of https://github.com/google/play-services-plugins/issues/246
# to generate the Configuration Cache regardless of incompatible tasks.
# See https://github.com/android/nowinandroid/issues/1022 before using it.
Expand Down

0 comments on commit 7de1154

Please sign in to comment.