diff --git a/plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/AndroidTestBaseAggregationPlugin.kt b/plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/AndroidTestBaseAggregationPlugin.kt index 2662a0f..3ca0c5a 100644 --- a/plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/AndroidTestBaseAggregationPlugin.kt +++ b/plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/AndroidTestBaseAggregationPlugin.kt @@ -2,7 +2,6 @@ package io.github.gmazzo.android.test.aggregation -import org.gradle.api.DomainObjectSet import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.provider.Property @@ -13,8 +12,6 @@ import org.gradle.kotlin.dsl.typeOf internal abstract class AndroidTestBaseAggregationPlugin : Plugin { - abstract val extendedProperties: DomainObjectSet> - override fun apply(target: Project): Unit = with(target) { apply(plugin = "com.android.base") @@ -22,20 +19,16 @@ internal abstract class AndroidTestBaseAggregationPlugin : Plugin { extensions.add( typeOf>(), ::aggregateTestCoverage.name, - objects.property().also(extendedProperties::add) + objects.property() ) } android.productFlavors.configureEach { extensions.add( typeOf>(), ::aggregateTestCoverage.name, - objects.property().also(extendedProperties::add) + objects.property() ) } - - androidComponents.finalizeDsl { - extendedProperties.all { finalizeValue() } - } } } diff --git a/plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/AndroidTestCoverageAggregationPlugin.kt b/plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/AndroidTestCoverageAggregationPlugin.kt index 3d2dcab..151a3d2 100644 --- a/plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/AndroidTestCoverageAggregationPlugin.kt +++ b/plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/AndroidTestCoverageAggregationPlugin.kt @@ -23,7 +23,6 @@ import org.gradle.kotlin.dsl.USAGE_TEST_AGGREGATION import org.gradle.kotlin.dsl.apply import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.get -import org.gradle.kotlin.dsl.getAt import org.gradle.kotlin.dsl.getValue import org.gradle.kotlin.dsl.listProperty import org.gradle.kotlin.dsl.named @@ -46,14 +45,14 @@ abstract class AndroidTestCoverageAggregationPlugin : Plugin { val jacocoVariants = objects.namedDomainObjectSet(Variant::class) androidComponents.onVariants { variant -> - val buildType = android.buildTypes[variant.buildType!!] - - if ((variant as? HasUnitTest)?.unitTest != null && - buildType.enableUnitTestCoverage && - android.shouldAggregate(variant) - ) { - jacocoVariants.add(variant) - } + jacocoVariants.addAllLater(provider { + val buildType = android.buildTypes[variant.buildType!!] + val aggregate = (variant as? HasUnitTest)?.unitTest != null && + buildType.enableUnitTestCoverage && + android.shouldAggregate(variant) + + if (aggregate) listOf(variant) else emptyList() + }) } configurations.create("codeCoverageExecutionData") { @@ -161,7 +160,6 @@ abstract class AndroidTestCoverageAggregationPlugin : Plugin { val robolectricSupport = objects.property() .convention(true) .apply { finalizeValueOnRead() } - .also(plugins.getAt(AndroidTestBaseAggregationPlugin::class).extendedProperties::add) (android as ExtensionAware).extensions .add("coverageRobolectricSupport", robolectricSupport) diff --git a/plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/AndroidTestResultsAggregationPlugin.kt b/plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/AndroidTestResultsAggregationPlugin.kt index 60401bd..3debf0c 100644 --- a/plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/AndroidTestResultsAggregationPlugin.kt +++ b/plugin/src/main/kotlin/io/github/gmazzo/android/test/aggregation/AndroidTestResultsAggregationPlugin.kt @@ -35,13 +35,11 @@ abstract class AndroidTestResultsAggregationPlugin : Plugin { } androidComponents.onVariants { variant -> - if ((variant as? HasUnitTest)?.unitTest != null && android.shouldAggregate(variant)) { - afterEvaluate { - val testTask = unitTestTaskOf(variant)!! + testResultsElements.outgoing.artifacts(provider { + val aggregate = (variant as? HasUnitTest)?.unitTest != null && android.shouldAggregate(variant) - testResultsElements.outgoing.artifact(testTask.flatMap { it.binaryResultsDirectory }) - } - } + if (aggregate) listOf(unitTestTaskOf(variant)!!.flatMap { it.binaryResultsDirectory }) else emptyList() + }) } }