diff --git a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/MarathonFlowAction.kt b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/MarathonFlowAction.kt new file mode 100644 index 000000000..81ccfc52e --- /dev/null +++ b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/MarathonFlowAction.kt @@ -0,0 +1,26 @@ +package com.malinskiy.marathon + +import org.gradle.api.flow.BuildWorkResult +import org.gradle.api.flow.FlowAction +import org.gradle.api.flow.FlowParameters +import org.gradle.api.provider.Property +import org.gradle.api.services.ServiceReference +import org.gradle.api.tasks.Input + +@Suppress("UnstableApiUsage") +abstract class MarathonFlowAction : FlowAction { + override fun execute(parameters: Params) { + // Consume build result + parameters.buildWorkResult.get() + + parameters.buildService.get().await() + } + + interface Params : FlowParameters { + @get:Input + val buildWorkResult: Property + + @get:ServiceReference + val buildService: Property + } +} diff --git a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/MarathonPlugin.kt b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/MarathonPlugin.kt index d23af513c..508fa81e0 100644 --- a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/MarathonPlugin.kt +++ b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/MarathonPlugin.kt @@ -10,14 +10,25 @@ import com.android.build.api.variant.Variant import com.malinskiy.marathon.android.findAdbPath import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.configuration.BuildFeatures +import org.gradle.api.flow.FlowProviders +import org.gradle.api.flow.FlowScope import org.gradle.api.plugins.JavaBasePlugin import org.gradle.api.tasks.TaskProvider +import org.gradle.kotlin.dsl.always import org.gradle.kotlin.dsl.create import org.gradle.kotlin.dsl.named import org.gradle.kotlin.dsl.register import org.gradle.kotlin.dsl.registerIfAbsent +import javax.inject.Inject + +@Suppress("UnstableApiUsage") +class MarathonPlugin @Inject constructor( + private val buildFeatures: BuildFeatures, + private val flowProviders: FlowProviders, + private val flowScope: FlowScope +) : Plugin { -class MarathonPlugin : Plugin { override fun apply(project: Project) { if (project.path == Project.PATH_SEPARATOR) { project.configureRootProject() @@ -43,7 +54,13 @@ class MarathonPlugin : Plugin { parameters.marathonConfig.set(marathonConfig) } - tasks.register(WORKER_TASK_NAME) + if (buildFeatures.isolatedProjects.active.get()) { + flowScope.always(MarathonFlowAction::class) { + parameters.buildWorkResult.set(flowProviders.buildWorkResult) + } + } else { + tasks.register(WORKER_TASK_NAME) + } } private fun Project.configureAndroidProject() { @@ -52,13 +69,12 @@ class MarathonPlugin : Plugin { description = "Runs all the instrumentation test variations on all the connected devices" } - val marathonWorkerTask = rootProject.tasks.named(WORKER_TASK_NAME) val androidComponents = extensions.getByType(AndroidComponentsExtension::class.java) androidComponents.onVariants { variant -> variant.components .filter { it is GeneratesTestApk } .forEach { component -> - val testTask = registerTestTask(variant, component, marathonWorkerTask) + val testTask = registerTestTask(variant, component) marathonTask.configure { dependsOn(testTask) } } } @@ -66,8 +82,7 @@ class MarathonPlugin : Plugin { private fun Project.registerTestTask( variant: Variant, - testComponent: Component, - marathonWorkerTask: TaskProvider + testComponent: Component ): TaskProvider = tasks.register(variant.computeTaskName(TASK_PREFIX, "androidTest")) { group = JavaBasePlugin.VERIFICATION_GROUP @@ -83,7 +98,9 @@ class MarathonPlugin : Plugin { is TestVariant -> testedApkDir.set(variant.testedApks) } - finalizedBy(marathonWorkerTask) + if (!buildFeatures.isolatedProjects.active.get()) { + finalizedBy(rootProject.tasks.named(WORKER_TASK_NAME)) + } } companion object { diff --git a/sample/gradle.properties b/sample/gradle.properties index 5642b96f7..b12e9c48e 100644 --- a/sample/gradle.properties +++ b/sample/gradle.properties @@ -2,6 +2,7 @@ org.gradle.caching=true org.gradle.configuration-cache=true org.gradle.jvmargs=-Xmx8g -XX:+UseParallelGC org.gradle.parallel=true +org.gradle.unsafe.isolated-projects=true kotlin.daemon.jvmargs=-Xmx1g -XX:+UseParallelGC android.useAndroidX=true