From 59acbe2a37b341de621db3d2914b37f69956e780 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Mon, 13 May 2024 02:07:36 +0530 Subject: [PATCH] fix(build): also inject test dependencies to androidTest source set --- .../dev/msfjarvis/claw/gradle/deps.ext.kt | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/build-logic/src/main/kotlin/dev/msfjarvis/claw/gradle/deps.ext.kt b/build-logic/src/main/kotlin/dev/msfjarvis/claw/gradle/deps.ext.kt index d1b291ec..6f499479 100644 --- a/build-logic/src/main/kotlin/dev/msfjarvis/claw/gradle/deps.ext.kt +++ b/build-logic/src/main/kotlin/dev/msfjarvis/claw/gradle/deps.ext.kt @@ -1,5 +1,5 @@ /* - * Copyright © 2023 Harsh Shandilya. + * Copyright © 2023-2024 Harsh Shandilya. * Use of this source code is governed by an MIT-style * license that can be found in the LICENSE file or at * https://opensource.org/licenses/MIT. @@ -16,19 +16,23 @@ import org.gradle.kotlin.dsl.exclude /** Extension function to configure JUnit5 dependencies with the Truth assertion library. */ fun DependencyHandlerScope.addTestDependencies(project: Project) { val libs = project.extensions.getByName("libs") as LibrariesForLibs - addProvider("testImplementation", libs.junit.jupiter.api) - addProvider( - "testImplementation", - libs.truth, - ) { - exclude(group = "junit", module = "junit") - } - addProvider("testRuntimeOnly", libs.junit.jupiter.engine) - addProvider( - "testRuntimeOnly", - libs.junit.legacy, - ) { - // See https://github.com/google/truth/issues/333 - because("Truth needs it") - } + arrayOf("test", "androidTest") + .filter { sourceSet -> project.configurations.findByName("${sourceSet}Implementation") != null } + .forEach { sourceSet -> + addProvider("${sourceSet}Implementation", libs.junit.jupiter.api) + addProvider( + "${sourceSet}Implementation", + libs.truth, + ) { + exclude(group = "junit", module = "junit") + } + addProvider("${sourceSet}RuntimeOnly", libs.junit.jupiter.engine) + addProvider( + "${sourceSet}RuntimeOnly", + libs.junit.legacy, + ) { + // See https://github.com/google/truth/issues/333 + because("Truth needs it") + } + } }