diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2021-07-19 16:31:37 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-19 16:31:37 +0530 |
commit | 392ad847bf522e2d3246e4fb62d4015b8c4b1d92 (patch) | |
tree | 479dddffd13e82a807f8769bab98e59c70ddeacf /buildSrc | |
parent | 921e9f96b9bec5e2bf8633947792d6991956507f (diff) |
Cleanup and fix CI tests (#1464)
Diffstat (limited to 'buildSrc')
-rw-r--r-- | buildSrc/src/main/java/BaseProjectConfig.kt | 19 | ||||
-rw-r--r-- | buildSrc/src/main/java/PasswordStorePlugin.kt | 2 | ||||
-rw-r--r-- | buildSrc/src/main/java/ProductFlavors.kt | 13 | ||||
-rw-r--r-- | buildSrc/src/main/java/SlimTests.kt | 38 |
4 files changed, 68 insertions, 4 deletions
diff --git a/buildSrc/src/main/java/BaseProjectConfig.kt b/buildSrc/src/main/java/BaseProjectConfig.kt index a829d4f7..e4dfa7e4 100644 --- a/buildSrc/src/main/java/BaseProjectConfig.kt +++ b/buildSrc/src/main/java/BaseProjectConfig.kt @@ -13,6 +13,7 @@ import org.gradle.api.tasks.wrapper.Wrapper import org.gradle.kotlin.dsl.maven import org.gradle.kotlin.dsl.repositories import org.gradle.kotlin.dsl.withType +import org.gradle.language.nativeplatform.internal.BuildType import org.jetbrains.kotlin.gradle.tasks.KotlinCompile /** @@ -50,9 +51,10 @@ internal fun Project.configureForAllProjects() { languageVersion = "1.5" } } - tasks.withType<Test> { + tasks.withType<Test>().configureEach { maxParallelForks = Runtime.getRuntime().availableProcessors() * 2 testLogging { events(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED) } + outputs.upToDateWhen { false } } } @@ -79,13 +81,19 @@ internal fun BaseAppModuleExtension.configureAndroidApplicationOptions(project: buildConfig = true } + flavorDimensions(FlavorDimensions.FREE) + productFlavors { + create(ProductFlavors.FREE) {} + create(ProductFlavors.NON_FREE) {} + } + buildTypes { - named("release") { + named(BuildType.RELEASE.name) { isMinifyEnabled = !minifySwitch.isPresent setProguardFiles(listOf("proguard-android-optimize.txt", "proguard-rules.pro")) buildConfigField("boolean", "ENABLE_DEBUG_FEATURES", "${project.isSnapshot()}") } - named("debug") { + named(BuildType.DEBUG.name) { applicationIdSuffix = ".debug" versionNameSuffix = "-debug" isMinifyEnabled = false @@ -121,5 +129,8 @@ internal fun TestedExtension.configureCommonAndroidOptions() { targetCompatibility = JavaVersion.VERSION_1_8 } - testOptions.animationsDisabled = true + testOptions { + animationsDisabled = true + unitTests.isReturnDefaultValues = true + } } diff --git a/buildSrc/src/main/java/PasswordStorePlugin.kt b/buildSrc/src/main/java/PasswordStorePlugin.kt index 0705de82..df491e0d 100644 --- a/buildSrc/src/main/java/PasswordStorePlugin.kt +++ b/buildSrc/src/main/java/PasswordStorePlugin.kt @@ -43,6 +43,7 @@ class PasswordStorePlugin : Plugin<Project> { is LibraryPlugin -> { project.extensions.getByType<TestedExtension>().configureCommonAndroidOptions() project.configureExplicitApi() + project.configureSlimTests() } is AppPlugin -> { project @@ -51,6 +52,7 @@ class PasswordStorePlugin : Plugin<Project> { .configureAndroidApplicationOptions(project) project.extensions.getByType<BaseAppModuleExtension>().configureBuildSigning(project) project.extensions.getByType<TestedExtension>().configureCommonAndroidOptions() + project.configureSlimTests() } is SigningPlugin -> { project.extensions.getByType<SigningExtension>().configureBuildSigning() diff --git a/buildSrc/src/main/java/ProductFlavors.kt b/buildSrc/src/main/java/ProductFlavors.kt new file mode 100644 index 00000000..5b722a37 --- /dev/null +++ b/buildSrc/src/main/java/ProductFlavors.kt @@ -0,0 +1,13 @@ +/* + * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. + * SPDX-License-Identifier: GPL-3.0-only + */ + +object FlavorDimensions { + const val FREE = "free" +} + +object ProductFlavors { + const val FREE = "free" + const val NON_FREE = "nonFree" +} diff --git a/buildSrc/src/main/java/SlimTests.kt b/buildSrc/src/main/java/SlimTests.kt new file mode 100644 index 00000000..65e9c618 --- /dev/null +++ b/buildSrc/src/main/java/SlimTests.kt @@ -0,0 +1,38 @@ +/* + * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. + * SPDX-License-Identifier: GPL-3.0-only + */ + +import com.android.build.api.extension.ApplicationAndroidComponentsExtension +import com.android.build.api.extension.LibraryAndroidComponentsExtension +import org.gradle.api.Project +import org.gradle.kotlin.dsl.findByType +import org.gradle.language.nativeplatform.internal.BuildType + +/** + * When the "slimTests" project property is provided, disable the unit test tasks on `release` build + * type and `nonFree` product flavor to avoid running the same tests repeatedly in different build + * variants. + * + * Examples: `./gradlew test -PslimTests` will run unit tests for `nonFreeDebug` and `debug` build + * variants in Android App and Library projects, and all tests in JVM projects. + */ +internal fun Project.configureSlimTests() { + if (providers.gradleProperty(SLIM_TESTS_PROPERTY).forUseAtConfigurationTime().isPresent) { + // disable unit test tasks on the release build type for Android Library projects + extensions.findByType<LibraryAndroidComponentsExtension>()?.run { + beforeUnitTests(selector().withBuildType(BuildType.RELEASE.name)) { it.enabled = false } + } + + // disable unit test tasks on the release build type and free flavor for Android Application + // projects. + extensions.findByType<ApplicationAndroidComponentsExtension>()?.run { + beforeUnitTests(selector().withBuildType(BuildType.RELEASE.name)) { it.enabled = false } + beforeUnitTests(selector().withFlavor(FlavorDimensions.FREE to ProductFlavors.NON_FREE)) { + it.enabled = false + } + } + } +} + +private const val SLIM_TESTS_PROPERTY = "slimTests" |