[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.
This commit is contained in:
Anton Lakotka
2023-12-05 13:32:04 +01:00
committed by Space Team
parent daa97f7ec9
commit 73b290a948
2 changed files with 35 additions and 0 deletions
@@ -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")
@@ -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()
}
}