@@ -4,6 +4,7 @@ import org.gradle.api.artifacts.VersionConstraint
44import org.gradle.api.artifacts.component.ComponentSelector
55import org.gradle.api.artifacts.component.ModuleComponentIdentifier
66import org.gradle.api.artifacts.component.ModuleComponentSelector
7+ import org.gradle.api.artifacts.component.ProjectComponentIdentifier
78import org.gradle.api.artifacts.result.DependencyResult
89import org.gradle.api.artifacts.result.ResolvedArtifactResult
910import org.gradle.api.artifacts.result.ResolvedComponentResult
@@ -42,28 +43,34 @@ interface IncludedJarInfo {
4243 ): IncludedJarInfo ? {
4344 val componentId = artifact.id.componentIdentifier
4445 val moduleSelector = selector as ? ModuleComponentSelector
45- val moduleIdentifier = componentId as ? ModuleComponentIdentifier
4646
47- val firstCapability = artifact.variant.capabilities.firstOrNull()
48-
49- val capability = if (moduleIdentifier != null ) {
50- // Try to find first variant that matches identifier, for consistency(matches MDG behavior)
51- artifact.variant.capabilities.firstOrNull {
52- it.group == moduleIdentifier.group &&
53- it.name == moduleIdentifier.module &&
54- it.version == moduleIdentifier.version
55- }
56- } else {
57- artifact.variant.capabilities.firstOrNull() ? : firstCapability
47+ val mainCapability = when (componentId) {
48+ is ModuleComponentIdentifier ->
49+ // Try to find first variant that matches identifier, for consistency(matches MDG behavior)
50+ artifact.variant.capabilities.firstOrNull {
51+ it.group == componentId.group &&
52+ it.name == componentId.module &&
53+ it.version == componentId.version
54+ }
55+
56+ is ProjectComponentIdentifier ->
57+ // Not in parity with MDG, but gets the capability that matches the project name for consistency with module capability behavior
58+ artifact.variant.capabilities.firstOrNull {
59+ it.name == componentId.projectName
60+ }
61+
62+ else -> null
5863 }
5964
65+ val capability = mainCapability ? : artifact.variant.capabilities.firstOrNull()
66+
6067 if (capability == null ) {
6168 return null
6269 }
6370
6471 val group = capability.group
6572 val name = capability.name
66- val version = capability.version ? : moduleIdentifier ?.version ? : moduleSelector?.version ? : " 0.0.0"
73+ val version = capability.version ? : (componentId as ? ModuleComponentIdentifier ) ?.version ? : moduleSelector?.version ? : " 0.0.0"
6774 val versionRange = versionRange(moduleSelector?.versionConstraint) ? : defaultVersionRange(version)
6875
6976 return objectFactory.newInstance<IncludedJarInfo >().also {
0 commit comments