Skip to content

Commit

Permalink
Simplify resolver to remove some special casing no longer needed (#826)
Browse files Browse the repository at this point in the history
- Also adds tests to verify kotlin stdlib behavior.
  • Loading branch information
tresat committed Jan 23, 2024
1 parent c02905d commit 2bbcccd
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,8 @@ class Resolver(
revision: String,
currentCoordinates: Map<Coordinate.Key, Coordinate>,
): Configuration {
// Kotlin deps anywhere in the hierarchy are a special case we'll handle later separately, unless they are being
// forced, as is the case with plugins, in which case handle those deps here
val kotlinDeps = { dependency: ExternalDependency -> (dependency.group?.startsWith("org.jetbrains.kotlin") ?: false) && dependency.version != null }
val latest = configuration.allDependencies
.filterIsInstance<ExternalDependency>()
.filterNot { kotlinDeps(it) && it.isForce }
.mapTo(mutableListOf()) { dependency ->
createQueryDependency(dependency as ModuleDependency)
}
Expand Down Expand Up @@ -123,11 +119,12 @@ class Resolver(
}

// Resolve using the latest version of explicitly declared dependencies and retains Kotlin's
// inherited stdlib dependencies from the super configurations. This is required for variant
// resolution, but the full set can break consumer capability matching.
// inherited dependencies (importantly, including stdlib) from the super configurations. This
// is required for variant resolution, but the full set can break consumer capability matching.
val isKotlinDep = { dependency: ExternalDependency -> (dependency.group?.startsWith("org.jetbrains.kotlin") ?: false) }
val inheritedKotlin = configuration.allDependencies
.filterIsInstance<ExternalDependency>()
.filter(kotlinDeps)
.filter { d -> isKotlinDep(d) }
.minus(configuration.dependencies)

// Adds the Kotlin 1.2.x legacy metadata to assist in variant selection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import spock.lang.Specification

import static org.gradle.testkit.runner.TaskOutcome.SUCCESS

final class PluginUpdateDetectionSpec extends Specification {
private static final KOTLIN_VERSION = '1.6.0'
final class KotlinDependencyUpdatesSpec extends Specification {
private static final DECLARED_KOTLIN_VERSION = '1.7.0'
private static final DECLARED_KOTLIN_STD_VERSION = '1.8.0'
private static final CURRENT_KOTLIN_VERSION = '2.0.0-Beta3'

@Rule
final TemporaryFolder testProjectDir = new TemporaryFolder()
Expand Down Expand Up @@ -45,7 +47,7 @@ final class PluginUpdateDetectionSpec extends Specification {
}
""".stripIndent()
testProjectDir.newFile('gradle.properties') << "kotlin_version = $KOTLIN_VERSION"
testProjectDir.newFile('gradle.properties') << "kotlin_version = $DECLARED_KOTLIN_VERSION"
when:
def result = GradleRunner.create()
Expand All @@ -56,7 +58,7 @@ final class PluginUpdateDetectionSpec extends Specification {
then:
result.output.contains """The following dependencies have later milestone versions:
- org.jetbrains.kotlin:kotlin-gradle-plugin [$KOTLIN_VERSION -> """
- org.jetbrains.kotlin:kotlin-gradle-plugin [$DECLARED_KOTLIN_VERSION -> $CURRENT_KOTLIN_VERSION]"""
result.task(':dependencyUpdates').outcome == SUCCESS
where:
Expand All @@ -83,7 +85,7 @@ final class PluginUpdateDetectionSpec extends Specification {
}
""".stripIndent()
testProjectDir.newFile('gradle.properties') << "kotlin_version = $KOTLIN_VERSION"
testProjectDir.newFile('gradle.properties') << "kotlin_version = $DECLARED_KOTLIN_VERSION"
when:
def result = GradleRunner.create()
Expand All @@ -94,7 +96,47 @@ final class PluginUpdateDetectionSpec extends Specification {
then:
result.output.contains """The following dependencies have later milestone versions:
- org.jetbrains.kotlin:kotlin-gradle-plugin [$KOTLIN_VERSION -> """
- org.jetbrains.kotlin:kotlin-gradle-plugin [$DECLARED_KOTLIN_VERSION -> $CURRENT_KOTLIN_VERSION]"""
result.task(':dependencyUpdates').outcome == SUCCESS
}
@See("https://github.com/ben-manes/gradle-versions-plugin/issues/423")
def "kotlin stdlib is properly handled (when added explicitly: #explicitStdLibVersion)"() {
given:
testProjectDir.newFile('build.gradle') <<
"""
plugins {
id 'com.github.ben-manes.versions' version '0.46.0'
id 'org.jetbrains.kotlin.jvm' version '$DECLARED_KOTLIN_VERSION'
}

repositories {
mavenCentral()
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib${explicitStdLibVersion ? ":$DECLARED_KOTLIN_STD_VERSION" : ""}"
}
""".stripIndent()
when:
def result = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withArguments('dependencyUpdates', '--info')
.withPluginClasspath()
.build()
then:
result.output.contains """The following dependencies have later milestone versions:
- org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable [$DECLARED_KOTLIN_VERSION -> $CURRENT_KOTLIN_VERSION]
https://kotlinlang.org/
- org.jetbrains.kotlin:kotlin-stdlib [${explicitStdLibVersion ? DECLARED_KOTLIN_STD_VERSION : DECLARED_KOTLIN_VERSION} -> $CURRENT_KOTLIN_VERSION]
https://kotlinlang.org/
- org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin [$DECLARED_KOTLIN_VERSION -> $CURRENT_KOTLIN_VERSION]
https://kotlinlang.org/"""
result.task(':dependencyUpdates').outcome == SUCCESS

where:
explicitStdLibVersion << [true, false]
}
}

0 comments on commit 2bbcccd

Please sign in to comment.