Use .withDependencies { ... } to set up default versions with Gradle 4.4
+ Improve the test for omitted Kotlin module versions. Issues: #KT-21806 Fixed, #KT-21203 Fixed
This commit is contained in:
+15
-4
@@ -10,6 +10,7 @@ import com.intellij.util.ReflectionUtil
|
||||
import groovy.lang.Closure
|
||||
import org.gradle.api.*
|
||||
import org.gradle.api.artifacts.Configuration
|
||||
import org.gradle.api.artifacts.ExternalDependency
|
||||
import org.gradle.api.file.ConfigurableFileCollection
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.file.SourceDirectorySet
|
||||
@@ -396,10 +397,20 @@ internal abstract class AbstractKotlinPlugin(
|
||||
|
||||
private fun configureDefaultVersionsResolutionStrategy(project: Project) {
|
||||
project.configurations.all { configuration ->
|
||||
configuration.resolutionStrategy.eachDependency { details ->
|
||||
val requested = details.requested
|
||||
if (requested.group == "org.jetbrains.kotlin" && requested.version.isEmpty()) {
|
||||
details.useVersion(kotlinPluginVersion)
|
||||
if (isGradleVersionAtLeast(4, 4)) {
|
||||
// Use the API introduced in Gradle 4.4 to modify the dependencies directly before they are resolved:
|
||||
configuration.withDependencies { dependencySet ->
|
||||
dependencySet.filterIsInstance<ExternalDependency>()
|
||||
.filter { it.group == "org.jetbrains.kotlin" && it.version.isNullOrEmpty() }
|
||||
.forEach { it.version { constraint -> constraint.prefer(kotlinPluginVersion) } }
|
||||
}
|
||||
}
|
||||
else {
|
||||
configuration.resolutionStrategy.eachDependency { details ->
|
||||
val requested = details.requested
|
||||
if (requested.group == "org.jetbrains.kotlin" && requested.version.isEmpty()) {
|
||||
details.useVersion(kotlinPluginVersion)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.utils
|
||||
|
||||
import org.gradle.util.GradleVersion
|
||||
|
||||
internal data class ParsedGradleVersion(val major: Int, val minor: Int) : Comparable<ParsedGradleVersion> {
|
||||
override fun compareTo(other: ParsedGradleVersion): Int {
|
||||
val majorCompare = major.compareTo(other.major)
|
||||
@@ -51,4 +53,8 @@ internal data class ParsedGradleVersion(val major: Int, val minor: Int) : Compar
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun isGradleVersionAtLeast(major: Int, minor: Int) =
|
||||
ParsedGradleVersion.parse(GradleVersion.current().version)
|
||||
?.let { it >= ParsedGradleVersion(major, minor) } ?: false
|
||||
Reference in New Issue
Block a user