Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Simplify resolver to remove some special casing no longer needed #826

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
}
}