[Gradle] test lazy resolved configuration can handle circular dependencies
In gradle it is possible to add dependency to configuration which is resolved to itself. It is possible due to nature of Configuration that can contain both: dependencies and artifacts. When configuration has dependency on itself, it practically means that this dependency will be resolved to configuration's artifacts. LazyResolvedConfiguration should be capable to handle such dependencies
This commit is contained in:
committed by
Space Team
parent
2b26b0c540
commit
938dd65881
+26
@@ -9,7 +9,9 @@ package org.jetbrains.kotlin.gradle.dependencyResolutionTests
|
||||
|
||||
import org.gradle.api.artifacts.Configuration
|
||||
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
|
||||
import org.gradle.api.artifacts.component.ProjectComponentIdentifier
|
||||
import org.gradle.internal.component.external.model.DefaultModuleComponentSelector
|
||||
import org.gradle.kotlin.dsl.project
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.kotlinToolingVersion
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.internal
|
||||
@@ -146,4 +148,28 @@ class LazyResolvedConfigurationTest {
|
||||
|
||||
if (lazyConfiguration.allResolvedDependencies.isNotEmpty()) fail("Expected no resolved dependencies")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test - circular dependency handling`() {
|
||||
val project = buildProject()
|
||||
val configuration = project.configurations.create("forTest")
|
||||
configuration.isCanBeConsumed = true
|
||||
// add dependency to itself
|
||||
project.dependencies.add(configuration.name, project.dependencies.project(":", configuration = configuration.name))
|
||||
project.artifacts.add(configuration.name, project.file("artifact.tmp"))
|
||||
|
||||
val lazyConfiguration = LazyResolvedConfiguration(configuration)
|
||||
|
||||
val dependency = lazyConfiguration.allResolvedDependencies.singleOrNull() ?: fail("Expected to have single dependency")
|
||||
val id = dependency.resolvedVariant.owner
|
||||
if (id !is ProjectComponentIdentifier || id.projectPath != ":") fail("Expected project(:) dependency")
|
||||
|
||||
val artifactName = lazyConfiguration
|
||||
.resolvedArtifacts
|
||||
.map { it.file.name }
|
||||
.singleOrNull()
|
||||
?: fail("Expected to have single artifact")
|
||||
|
||||
assertEquals("artifact.tmp", artifactName)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user