Skip to content

Commit

Permalink
Locks are applied with resolutionStrategy.dependencySubstitution.subs…
Browse files Browse the repository at this point in the history
…titute instead of resolutionStrategy.eachDependency with useVersion to assist with core gradle alignment platform edges

Core Gradle alignment does not apply `useVersion`/`useTarget` to virtual platforms, which make up aligned groups. Instead, this more specific DSL of dependencySubstitution is used and applied to virtual platforms.

For the cases where there is a non-locked alignment rule that causes a resolution difference to that seen in the lock file, the resolved version will equal the locked version with Nebula alignment and resolution will fail due to `Multiple forces on different versions for virtual platform` with core Gradle alignment (causing the user to make a change or update their locks)

Without this change, this case above with core Gradle alignment would result in the locked version and the new aligned version entering conflict resolution and the locked version may no longer be the final resolved version.
  • Loading branch information
OdysseusLives committed Sep 23, 2020
1 parent 7b4563c commit 84252a1
Show file tree
Hide file tree
Showing 2 changed files with 561 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.DependencyResolveDetails
import org.gradle.api.artifacts.DependencySubstitutions
import org.gradle.api.artifacts.ExternalDependency
import org.gradle.api.logging.Logger
import org.gradle.api.logging.Logging
Expand Down Expand Up @@ -277,15 +278,17 @@ class DependencyLockPlugin : Plugin<Project> {
}

private fun lockConfiguration(conf: Configuration, selectorKeys: List<ModuleVersionSelectorKey>) {
val selectorsByKey = selectorKeys.groupBy { it }.mapValues { it.key }
conf.resolutionStrategy.eachDependency { details ->
val moduleKey = details.toKey()
val module = selectorsByKey[moduleKey]
if (module != null) {
details.because("${moduleKey.toModuleString()} locked to ${module.version}\n" +
"\twith reasons: ${reasons.joinToString()}")
.useVersion(module.version!!)
}
val resolutionStrategySubstitution: DependencySubstitutions = conf.resolutionStrategy.dependencySubstitution
selectorKeys.forEach { key ->
val substitutedModule = resolutionStrategySubstitution.module("${key.group}:${key.name}")
val withModule = resolutionStrategySubstitution.module("${key.group}:${key.name}:${key.version}")

val substitutionMessage = "${key.group}:${key.name} locked to ${key.version}\n" +
"\twith reasons: ${reasons.joinToString()}"

resolutionStrategySubstitution.substitute(substitutedModule)
.because(substitutionMessage)
.with(withModule)
}
}

Expand Down

0 comments on commit 84252a1

Please sign in to comment.