Clean up eager creation of test tasks in build.gradle files
Test: None
Change-Id: Ifdbd72eb173e33633ee4cb69e6ef36e35e2469a6
diff --git a/compose/compiler/compiler-hosted/integration-tests/build.gradle b/compose/compiler/compiler-hosted/integration-tests/build.gradle
index a3eec6e0..56f9a0d 100644
--- a/compose/compiler/compiler-hosted/integration-tests/build.gradle
+++ b/compose/compiler/compiler-hosted/integration-tests/build.gradle
@@ -101,18 +101,16 @@
namespace "androidx.compose.runtime.tests"
}
-afterEvaluate {
- tasks.withType(Test) { t ->
- t.dependsOn(":compose:compiler:compiler:embeddedPlugin")
-
- maxHeapSize("1024m")
- t.jvmArgs += ["--add-opens=jdk.jdi/com.sun.tools.jdi=ALL-UNNAMED"]
+tasks.withType(Test).configureEach { test ->
+ test.dependsOn(":compose:compiler:compiler:embeddedPlugin")
+ test.maxHeapSize("1024m")
+ test.jvmArgs += ["--add-opens=jdk.jdi/com.sun.tools.jdi=ALL-UNNAMED"]
+ if (test.name == "test") {
+ // The compose compiler debugger runs on desktop in AndroidStudio, and so the debugger test is
+ // implemented as a desktop test to avoid the need to inject tools.jar (from desktop jvm) into
+ // android tests
+ test.dependsOn("desktopTest")
}
-
- // The compose compiler debugger runs on desktop in AndroidStudio, and so the debugger test is
- // implemented as a desktop test to avoid the need to inject tools.jar (from desktop jvm) into
- // android tests
- tasks.findByPath("test").dependsOn(tasks.findByPath("desktopTest"))
}
androidx {
diff --git a/compose/compiler/compiler/integration-tests/build.gradle b/compose/compiler/compiler/integration-tests/build.gradle
index 8c81a67..315e0db 100644
--- a/compose/compiler/compiler/integration-tests/build.gradle
+++ b/compose/compiler/compiler/integration-tests/build.gradle
@@ -38,10 +38,11 @@
SdkResourceGenerator.generateForHostTest(project)
-def testTask = tasks.findByPath("test")
-testTask.dependsOn(tasks.findByPath(":compose:compiler:compiler:publish"))
-if (!isPlayground(project)) {
- testTask.dependsOn(tasks.findByPath(":compose:runtime:runtime:publish"))
- testTask.dependsOn(tasks.findByPath(":collection:collection:publish"))
- testTask.dependsOn(tasks.findByPath(":annotation:annotation:publish"))
+tasks.withType(Test).configureEach { test ->
+ test.dependsOn(":compose:compiler:compiler:publish")
+ if (!isPlayground(project)) {
+ test.dependsOn(":compose:runtime:runtime:publish")
+ test.dependsOn(":collection:collection:publish")
+ test.dependsOn(":annotation:annotation:publish")
+ }
}
diff --git a/compose/desktop/desktop/build.gradle b/compose/desktop/desktop/build.gradle
index bd475f5..0dc6488 100644
--- a/compose/desktop/desktop/build.gradle
+++ b/compose/desktop/desktop/build.gradle
@@ -91,7 +91,7 @@
}
// Set golden images path based on whether this is the GitHub or AndroidX repo.
-tasks.findByName("jvmTest").configure {
+tasks.withType(Test).configureEach {
systemProperties["GOLDEN_PATH"] = getGoldenPath(project).toString()
}
diff --git a/compose/ui/ui-graphics/build.gradle b/compose/ui/ui-graphics/build.gradle
index 3ceef91..e95cbdd 100644
--- a/compose/ui/ui-graphics/build.gradle
+++ b/compose/ui/ui-graphics/build.gradle
@@ -155,7 +155,9 @@
}
if (KmpPlatformsKt.enableDesktop(project)) {
- tasks.findByName("desktopTest").configure {
- systemProperties["GOLDEN_PATH"] = project.rootDir.absolutePath + "/../../golden"
+ tasks.withType(Test).configureEach {
+ if (name.equals("desktopTest")) {
+ systemProperties["GOLDEN_PATH"] = project.rootDir.absolutePath + "/../../golden"
+ }
}
}
\ No newline at end of file
diff --git a/compose/ui/ui/build.gradle b/compose/ui/ui/build.gradle
index 000723b..a866f51 100644
--- a/compose/ui/ui/build.gradle
+++ b/compose/ui/ui/build.gradle
@@ -234,8 +234,10 @@
}
if (KmpPlatformsKt.enableDesktop(project)) {
- tasks.findByName("desktopTest").configure {
- systemProperties["GOLDEN_PATH"] = project.rootDir.absolutePath + "/../../golden"
+ tasks.withType(Test).configureEach {
+ if (name.equals("desktopTest")) {
+ systemProperties["GOLDEN_PATH"] = project.rootDir.absolutePath + "/../../golden"
+ }
}
}
diff --git a/lifecycle/integration-tests/incrementality/build.gradle b/lifecycle/integration-tests/incrementality/build.gradle
index 3b547a5..7a8cfcf 100644
--- a/lifecycle/integration-tests/incrementality/build.gradle
+++ b/lifecycle/integration-tests/incrementality/build.gradle
@@ -39,11 +39,13 @@
SdkResourceGenerator.generateForHostTest(project)
// lifecycle-common and annotation are the dependencies of lifecycle-compiler
-tasks.findByPath("test").configure {
- dependsOn(":lifecycle:lifecycle-compiler:publish")
- dependsOn(":lifecycle:lifecycle-common:publish")
- dependsOn(":lifecycle:lifecycle-runtime:publish")
- dependsOn(":annotation:annotation:publish")
- dependsOn(":arch:core:core-common:publish")
- dependsOn(":arch:core:core-runtime:publish")
+tasks.withType(Test).configureEach { test ->
+ test.dependsOn(
+ ":lifecycle:lifecycle-compiler:publish",
+ ":lifecycle:lifecycle-common:publish",
+ ":lifecycle:lifecycle-runtime:publish",
+ ":annotation:annotation:publish",
+ ":arch:core:core-common:publish",
+ ":arch:core:core-runtime:publish"
+ )
}
diff --git a/privacysandbox/tools/tools-apicompiler/build.gradle b/privacysandbox/tools/tools-apicompiler/build.gradle
index 670f655..f1f5a3b 100644
--- a/privacysandbox/tools/tools-apicompiler/build.gradle
+++ b/privacysandbox/tools/tools-apicompiler/build.gradle
@@ -60,18 +60,18 @@
def aidlCompilerPath = "${SdkHelperKt.getSdkPath(project)}/build-tools/$buildToolsVersion/aidl"
def frameworkAidlPath = "${SdkHelperKt.getSdkPath(project)}/platforms/$compileSdk/framework.aidl"
def testGeneratedSourcesPath = "${project.buildDir}/testGeneratedSources"
-test {
- inputs.files(aidlCompilerPath)
+tasks.withType(Test).configureEach { test ->
+ test.inputs.files(aidlCompilerPath)
.withPropertyName("aidl_compiler_path")
.withPathSensitivity(PathSensitivity.NAME_ONLY)
- inputs.files(frameworkAidlPath)
+ test.inputs.files(frameworkAidlPath)
.withPropertyName("framework_aidl_path")
.withPathSensitivity(PathSensitivity.NAME_ONLY)
- inputs.dir("src/test/test-data").withPathSensitivity(PathSensitivity.RELATIVE)
- doFirst {
- systemProperty "aidl_compiler_path", aidlCompilerPath
- systemProperty "framework_aidl_path", frameworkAidlPath
- systemProperty "test_output_dir", testGeneratedSourcesPath
+ test.inputs.dir("src/test/test-data").withPathSensitivity(PathSensitivity.RELATIVE)
+ test.doFirst {
+ systemProperty("aidl_compiler_path", aidlCompilerPath)
+ systemProperty("framework_aidl_path", frameworkAidlPath)
+ systemProperty("test_output_dir", testGeneratedSourcesPath)
}
}
diff --git a/privacysandbox/tools/tools-apigenerator/build.gradle b/privacysandbox/tools/tools-apigenerator/build.gradle
index b461f26..a6ba53c 100644
--- a/privacysandbox/tools/tools-apigenerator/build.gradle
+++ b/privacysandbox/tools/tools-apigenerator/build.gradle
@@ -66,15 +66,15 @@
def aidlCompilerPath = "${SdkHelperKt.getSdkPath(project)}/build-tools/$buildToolsVersion/aidl"
def frameworkAidlPath = "${SdkHelperKt.getSdkPath(project)}/platforms/$compileSdk/framework.aidl"
def testGeneratedSourcesPath = "${project.buildDir}/testGeneratedSources"
-test {
- inputs.files(aidlCompilerPath)
+tasks.withType(Test).configureEach { test ->
+ test.inputs.files(aidlCompilerPath)
.withPropertyName("aidl_compiler_path")
.withPathSensitivity(PathSensitivity.NAME_ONLY)
- inputs.files(frameworkAidlPath)
+ test.inputs.files(frameworkAidlPath)
.withPropertyName("framework_aidl_path")
.withPathSensitivity(PathSensitivity.NAME_ONLY)
- inputs.dir("src/test/test-data").withPathSensitivity(PathSensitivity.RELATIVE)
- doFirst {
+ test.inputs.dir("src/test/test-data").withPathSensitivity(PathSensitivity.RELATIVE)
+ test.doFirst {
systemProperty "aidl_compiler_path", aidlCompilerPath
systemProperty "framework_aidl_path", frameworkAidlPath
systemProperty "test_output_dir", testGeneratedSourcesPath
diff --git a/privacysandbox/tools/tools-core/build.gradle b/privacysandbox/tools/tools-core/build.gradle
index 633bba0..fbc42d4 100644
--- a/privacysandbox/tools/tools-core/build.gradle
+++ b/privacysandbox/tools/tools-core/build.gradle
@@ -54,15 +54,15 @@
// Get AIDL compiler path and framework.aidl path and pass to tests for code generation.
def aidlCompilerPath = "${SdkHelperKt.getSdkPath(project)}/build-tools/$buildToolsVersion/aidl"
def frameworkAidlPath = "${SdkHelperKt.getSdkPath(project)}/platforms/$compileSdk/framework.aidl"
-test {
- inputs.files(aidlCompilerPath)
+tasks.withType(Test).configureEach { test ->
+ test.inputs.files(aidlCompilerPath)
.withPropertyName("aidl_compiler_path")
.withPathSensitivity(PathSensitivity.NAME_ONLY)
- inputs.files(frameworkAidlPath)
+ test.inputs.files(frameworkAidlPath)
.withPropertyName("framework_aidl_path")
.withPathSensitivity(PathSensitivity.NAME_ONLY)
- inputs.dir("src/test/test-data").withPathSensitivity(PathSensitivity.RELATIVE)
- doFirst {
+ test.inputs.dir("src/test/test-data").withPathSensitivity(PathSensitivity.RELATIVE)
+ test.doFirst {
systemProperty "aidl_compiler_path", aidlCompilerPath
systemProperty "framework_aidl_path", frameworkAidlPath
}
diff --git a/room/integration-tests/incremental-annotation-processing/build.gradle b/room/integration-tests/incremental-annotation-processing/build.gradle
index 3821f46..b7c89e0 100644
--- a/room/integration-tests/incremental-annotation-processing/build.gradle
+++ b/room/integration-tests/incremental-annotation-processing/build.gradle
@@ -39,14 +39,16 @@
SdkResourceGenerator.generateForHostTest(project)
-tasks.findByPath("test").dependsOn(
- tasks.findByPath(":annotation:annotation:publish"),
- tasks.findByPath(":annotation:annotation-experimental:publish"),
- tasks.findByPath(":room:room-common:publish"),
- tasks.findByPath(":room:room-runtime:publish"),
- tasks.findByPath(":room:room-migration:publish"),
- tasks.findByPath(":room:room-compiler:publish"),
- tasks.findByPath(":room:room-compiler-processing:publish"),
- tasks.findByPath(":sqlite:sqlite:publish"),
- tasks.findByPath(":sqlite:sqlite-framework:publish"),
-)
\ No newline at end of file
+tasks.withType(Test).configureEach { test ->
+ test.dependsOn(
+ ":annotation:annotation:publish",
+ ":annotation:annotation-experimental:publish",
+ ":room:room-common:publish",
+ ":room:room-runtime:publish",
+ ":room:room-migration:publish",
+ ":room:room-compiler:publish",
+ ":room:room-compiler-processing:publish",
+ ":sqlite:sqlite:publish",
+ ":sqlite:sqlite-framework:publish",
+ )
+}
diff --git a/room/room-gradle-plugin/build.gradle b/room/room-gradle-plugin/build.gradle
index 02738a1..d3ac542 100644
--- a/room/room-gradle-plugin/build.gradle
+++ b/room/room-gradle-plugin/build.gradle
@@ -73,22 +73,21 @@
// once we move to AGP 8.2.1+
languageVersion = JavaLanguageVersion.of(17)
}
+ // Configure publishing tasks to be dependencies of 'test' so those artifacts are available for
+ // the test project executed with Gradle Test Kit.
+ test.dependsOn(
+ ":annotation:annotation:publish",
+ ":annotation:annotation-experimental:publish",
+ ":room:room-common:publish",
+ ":room:room-runtime:publish",
+ ":room:room-migration:publish",
+ ":room:room-compiler:publish",
+ ":room:room-compiler-processing:publish",
+ ":sqlite:sqlite:publish",
+ ":sqlite:sqlite-framework:publish",
+ )
}
-// Configure publishing tasks to be dependencies of 'test' so those artifacts are available for
-// the test project executed with Gradle Test Kit.
-tasks.findByPath("test").dependsOn(
- tasks.findByPath(":annotation:annotation:publish"),
- tasks.findByPath(":annotation:annotation-experimental:publish"),
- tasks.findByPath(":room:room-common:publish"),
- tasks.findByPath(":room:room-runtime:publish"),
- tasks.findByPath(":room:room-migration:publish"),
- tasks.findByPath(":room:room-compiler:publish"),
- tasks.findByPath(":room:room-compiler-processing:publish"),
- tasks.findByPath(":sqlite:sqlite:publish"),
- tasks.findByPath(":sqlite:sqlite-framework:publish"),
-)
-
gradlePlugin {
plugins {
room {