From 73b290a94831a1aee547c99ab319fafc311864d7 Mon Sep 17 00:00:00 2001 From: Anton Lakotka Date: Tue, 5 Dec 2023 13:32:04 +0100 Subject: [PATCH] [Gradle] suppress DependencySources configurations in tests PreHmppDependenciesDeprecationIT test checks that all configurations are resolved without any error. However, *DependencySources configurations by nature can't be resolved all the time. As not all dependencies have sources variants published. --- .../mpp/PreHmppDependenciesDeprecationIT.kt | 1 + .../kotlin/gradle/testbase/testDsl.kt | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/mpp/PreHmppDependenciesDeprecationIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/mpp/PreHmppDependenciesDeprecationIT.kt index 4fe162b8043..39b66df4778 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/mpp/PreHmppDependenciesDeprecationIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/mpp/PreHmppDependenciesDeprecationIT.kt @@ -86,6 +86,7 @@ class PreHmppDependenciesDeprecationIT : KGPBaseTest() { ) { project("preHmppDependenciesDeprecation/$projectName", gradleVersion, localRepoDir = tempDir?.resolve("repo")) { preBuildAction() + suppressDependencySourcesConfigurations() build("$projectPathToCheck:dependencies") { // all dependencies should be resolved, Gradle won't fail the 'dependencies' task on its own assertOutputDoesNotContain("FAILED") diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/testbase/testDsl.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/testbase/testDsl.kt index ac2a30dc31c..dc218a0ffb6 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/testbase/testDsl.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/testbase/testDsl.kt @@ -720,3 +720,37 @@ internal fun TestProject.enableStableConfigurationCachePreview() { """.trimMargin() ) } + +/** + * Kotlin Multiplatform Projects have dedicated configurations for source files resolution of all source set dependencies + * This helper can be useful for cases when you want to resolve a bunch of configurations and don't want to see any unexpected failures + * coming from *DependencySources configurations. Because by nature not every published library has sources variants that can be resolved + * via gradle Configurations. + */ +internal fun TestProject.suppressDependencySourcesConfigurations() { + if (buildGradleKts.exists()) { + buildGradleKts.appendText( + """ + allprojects { + configurations.configureEach { + if (name.endsWith("DependencySources") || name.endsWith("dependencySources")) { + incoming.beforeResolve { setExtendsFrom(emptySet()) } + } + } + } + """.trimIndent() + ) + } else if (buildGradle.exists()) { + """ + allprojects { + configurations { + configureEach { + if (name.endsWith("DependencySources") || name.endsWith("dependencySources")) { + incoming.beforeResolve { setExtendsFrom([]) } + } + } + } + } + """.trimIndent() + } +} \ No newline at end of file