mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 10:37:05 +05:30
feat(build-logic): port slimTests
from APS
This commit is contained in:
parent
2594c172f0
commit
528e3c7821
2 changed files with 34 additions and 1 deletions
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
@ -26,7 +26,7 @@ jobs:
|
||||||
- name: Run unit tests
|
- name: Run unit tests
|
||||||
uses: gradle/gradle-build-action@v2.3.0
|
uses: gradle/gradle-build-action@v2.3.0
|
||||||
with:
|
with:
|
||||||
arguments: check --stacktrace --no-configuration-cache
|
arguments: check -PslimTests --stacktrace --no-configuration-cache
|
||||||
gradle-home-cache-cleanup: true
|
gradle-home-cache-cleanup: true
|
||||||
|
|
||||||
- name: (Fail-only) Upload test report
|
- name: (Fail-only) Upload test report
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package dev.msfjarvis.aps.gradle
|
package dev.msfjarvis.aps.gradle
|
||||||
|
|
||||||
import com.android.build.api.dsl.TestExtension
|
import com.android.build.api.dsl.TestExtension
|
||||||
|
import com.android.build.api.variant.ApplicationAndroidComponentsExtension
|
||||||
|
import com.android.build.api.variant.LibraryAndroidComponentsExtension
|
||||||
import com.android.build.gradle.TestedExtension
|
import com.android.build.gradle.TestedExtension
|
||||||
import org.gradle.android.AndroidCacheFixPlugin
|
import org.gradle.android.AndroidCacheFixPlugin
|
||||||
import org.gradle.api.JavaVersion
|
import org.gradle.api.JavaVersion
|
||||||
|
@ -9,9 +11,12 @@ import org.gradle.api.Project
|
||||||
import org.gradle.kotlin.dsl.apply
|
import org.gradle.kotlin.dsl.apply
|
||||||
import org.gradle.kotlin.dsl.findByType
|
import org.gradle.kotlin.dsl.findByType
|
||||||
|
|
||||||
|
private const val SLIM_TESTS_PROPERTY = "slimTests"
|
||||||
|
|
||||||
@Suppress("UnstableApiUsage")
|
@Suppress("UnstableApiUsage")
|
||||||
class AndroidCommonPlugin : Plugin<Project> {
|
class AndroidCommonPlugin : Plugin<Project> {
|
||||||
override fun apply(project: Project) {
|
override fun apply(project: Project) {
|
||||||
|
project.configureSlimTests()
|
||||||
project.pluginManager.apply(AndroidCacheFixPlugin::class)
|
project.pluginManager.apply(AndroidCacheFixPlugin::class)
|
||||||
project.extensions.findByType<TestedExtension>()?.run {
|
project.extensions.findByType<TestedExtension>()?.run {
|
||||||
setCompileSdkVersion(33)
|
setCompileSdkVersion(33)
|
||||||
|
@ -63,3 +68,31 @@ class AndroidCommonPlugin : Plugin<Project> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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).isPresent) {
|
||||||
|
// Disable unit test tasks on the release build type for Android Library projects
|
||||||
|
extensions.findByType<LibraryAndroidComponentsExtension>()?.run {
|
||||||
|
beforeVariants(selector().withBuildType("release")) {
|
||||||
|
it.enableUnitTest = false
|
||||||
|
it.enableAndroidTest = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable unit test tasks on the release build type for Android Application projects.
|
||||||
|
extensions.findByType<ApplicationAndroidComponentsExtension>()?.run {
|
||||||
|
beforeVariants(selector().withBuildType("release")) {
|
||||||
|
it.enableUnitTest = false
|
||||||
|
it.enableAndroidTest = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue