Skip to content

Commit

Permalink
Fixed broken integration when com.android.test plugin is applied
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazzo committed Jun 3, 2023
1 parent d184cdb commit f35d766
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
alias(libs.plugins.android) apply false
alias(libs.plugins.android.lib) apply false
alias(libs.plugins.android.test) apply false
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.kotlin.android) apply false
}
Expand Down
15 changes: 15 additions & 0 deletions demo-project/ui-tests/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
plugins {
alias(libs.plugins.android.test)
alias(libs.plugins.kotlin.android)
}

android {
namespace = "com.example.app.test"
compileSdk = 33

targetProjectPath = projects.demoProject.app.dependencyProject.path

defaultConfig {
missingDimensionStrategy("environment", "stage")
}
}
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ robolectric = "org.robolectric:robolectric:4.10.3"
[plugins]
android = { id = "com.android.application", version.ref = "agp" }
android-lib = { id = "com.android.library", version.ref = "agp" }
android-test = { id = "com.android.test", version.ref = "agp" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-samReceiver = { id = "org.jetbrains.kotlin.plugin.sam.with.receiver", version.ref = "kotlin" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.gmazzo.android.test.aggregation

import com.android.build.gradle.TestedExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.attributes.Category
Expand Down Expand Up @@ -30,7 +31,7 @@ abstract class AndroidTestResultsAggregationPlugin : Plugin<Project> {
objects.named(VerificationType.TEST_RESULTS)
)
}
android.unitTestVariants.all {
(android as? TestedExtension)?.unitTestVariants?.all {
val testTask = tasks.named<Test>("test${name.capitalized()}")

outgoing.artifact(testTask.flatMap { it.binaryResultsDirectory })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.gmazzo.android.test.aggregation

import com.android.build.api.variant.AndroidComponentsExtension
import com.android.build.gradle.TestedExtension
import com.android.build.gradle.BaseExtension
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.kotlin.dsl.create
Expand All @@ -11,7 +11,7 @@ import org.gradle.kotlin.dsl.testAggregation
import org.gradle.kotlin.dsl.the

internal val Project.android
get() = the<TestedExtension>()
get() = the<BaseExtension>()

internal val Project.androidComponents
get() = extensions.getByName<AndroidComponentsExtension<*, *, *>>("androidComponents")
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ includeBuild("plugin")
include("demo-project:app")
include("demo-project:domain")
include("demo-project:login")
include("demo-project:ui-tests")

0 comments on commit f35d766

Please sign in to comment.