Set default stdlib dependency to kotlin-stdlib-jdk8
^KT-53830 Fixed
This commit is contained in:
-2
@@ -15,7 +15,6 @@ import org.jetbrains.kotlin.gradle.tooling.BuildKotlinToolingMetadataTask
|
||||
import org.jetbrains.kotlin.gradle.util.*
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import org.junit.Assume
|
||||
import org.junit.Ignore
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import java.util.zip.ZipFile
|
||||
@@ -793,7 +792,6 @@ open class KotlinAndroid71GradleIT : KotlinAndroid70GradleIT() {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Due to KT-51907, remove after fixing stdlib auto-configuration")
|
||||
fun `test associate compilation dependencies are passed correctly to android test compilations`() {
|
||||
with(Project("kt-49877")) {
|
||||
build("allTests") {
|
||||
|
||||
+4
-3
@@ -201,14 +201,15 @@ class KotlinSpecificDependenciesIT : KGPBaseTest() {
|
||||
buildGradle.appendText(
|
||||
"""
|
||||
|
||||
dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") }
|
||||
dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib") }
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
// Check that the explicit stdlib overrides the plugin's choice of stdlib-jdk8
|
||||
checkTaskCompileClasspath(
|
||||
"compileKotlin",
|
||||
listOf("kotlin-stdlib-jdk8-${defaultBuildOptions.kotlinVersion}")
|
||||
listOf("kotlin-stdlib-${defaultBuildOptions.kotlinVersion}"),
|
||||
listOf("kotlin-stdlib-jdk8")
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -545,7 +546,7 @@ class KotlinSpecificDependenciesIT : KGPBaseTest() {
|
||||
|
||||
checkTaskCompileClasspath(
|
||||
"compileTestKotlin",
|
||||
listOf("kotlin-stdlib-jdk8-", "kotlin-reflect-", "kotlin-test-").map { it + customVersion }
|
||||
listOf("kotlin-stdlib-", "kotlin-reflect-", "kotlin-test-").map { it + customVersion }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -106,7 +106,7 @@ class PublishingIT : KGPBaseTest() {
|
||||
) {
|
||||
assertTasksExecuted(":compileKotlin", ":compileTestKotlin")
|
||||
val pomLines = projectPath.resolve("build/publications/myLibrary/pom-default.xml").readLines()
|
||||
val stdlibVersionLineNumber = pomLines.indexOfFirst { "<artifactId>kotlin-stdlib</artifactId>" in it } + 1
|
||||
val stdlibVersionLineNumber = pomLines.indexOfFirst { "<artifactId>kotlin-stdlib-jdk8</artifactId>" in it } + 1
|
||||
val versionLine = pomLines[stdlibVersionLineNumber]
|
||||
assertTrue { "<version>${buildOptions.kotlinVersion}</version>" in versionLine }
|
||||
}
|
||||
|
||||
+5
-19
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.gradle.plugin.sources.android.AndroidVariantType
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.android.androidSourceSetInfoOrNull
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.dependsOnClosure
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.sourceSetDependencyConfigurationByScope
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.SemVer
|
||||
|
||||
internal fun Project.configureStdlibDefaultDependency(
|
||||
topLevelExtension: KotlinTopLevelExtension,
|
||||
@@ -66,7 +65,7 @@ private fun addStdlibToKpmProject(
|
||||
val dependencyHandler = project.dependencies
|
||||
val stdlibModule = when (variant.platformType) {
|
||||
KotlinPlatformType.common -> error("variants are not expected to be common")
|
||||
KotlinPlatformType.jvm -> chooseStdlibJvmDependency(coreLibrariesVersion)
|
||||
KotlinPlatformType.jvm -> "kotlin-stdlib-jdk8"
|
||||
KotlinPlatformType.js -> "kotlin-stdlib-js"
|
||||
KotlinPlatformType.wasm -> "kotlin-stdlib-wasm"
|
||||
KotlinPlatformType.androidJvm -> null // TODO: expect support on the AGP side?
|
||||
@@ -106,10 +105,11 @@ private fun KotlinTarget.addStdlibDependency(
|
||||
|
||||
val stdlibModule = compilation
|
||||
.platformType
|
||||
.stdlibPlatformType(coreLibrariesVersion, this, kotlinSourceSet)
|
||||
.stdlibPlatformType( this, kotlinSourceSet)
|
||||
?: return@withDependencies
|
||||
|
||||
// Check if stdlib module is added to SourceSets hierarchy
|
||||
@Suppress("DEPRECATION")
|
||||
if (
|
||||
isStdlibAddedByUser(
|
||||
configurations,
|
||||
@@ -147,16 +147,15 @@ private fun isStdlibAddedByUser(
|
||||
}
|
||||
|
||||
private fun KotlinPlatformType.stdlibPlatformType(
|
||||
coreLibrariesVersion: Provider<String>,
|
||||
kotlinTarget: KotlinTarget,
|
||||
kotlinSourceSet: KotlinSourceSet
|
||||
): String? = when (this) {
|
||||
KotlinPlatformType.jvm -> chooseStdlibJvmDependency(coreLibrariesVersion)
|
||||
KotlinPlatformType.jvm -> "kotlin-stdlib-jdk8"
|
||||
KotlinPlatformType.androidJvm -> {
|
||||
if (kotlinTarget is KotlinAndroidTarget &&
|
||||
kotlinSourceSet.androidSourceSetInfoOrNull?.androidSourceSetName == AndroidBaseSourceSetName.Main.name
|
||||
) {
|
||||
chooseStdlibJvmDependency(coreLibrariesVersion)
|
||||
"kotlin-stdlib-jdk8"
|
||||
} else {
|
||||
null
|
||||
}
|
||||
@@ -169,19 +168,6 @@ private fun KotlinPlatformType.stdlibPlatformType(
|
||||
"kotlin-stdlib-common"
|
||||
}
|
||||
|
||||
private val kotlin180Version = SemVer(1.toBigInteger(), 8.toBigInteger(), 0.toBigInteger())
|
||||
|
||||
private fun chooseStdlibJvmDependency(
|
||||
coreLibrariesVersion: Provider<String>
|
||||
): String {
|
||||
// Current 'SemVer.satisfies' release always returns `false` for any "-SNAPSHOT" version.
|
||||
return if (SemVer.from(coreLibrariesVersion.get()) < kotlin180Version) {
|
||||
"kotlin-stdlib-jdk8"
|
||||
} else {
|
||||
"kotlin-stdlib"
|
||||
}
|
||||
}
|
||||
|
||||
private val androidTestVariants = setOf(AndroidVariantType.UnitTest, AndroidVariantType.InstrumentedTest)
|
||||
|
||||
private fun KotlinSourceSet.isRelatedToAndroidTestSourceSet(): Boolean {
|
||||
|
||||
+2
@@ -149,6 +149,8 @@ class StdlibKotlinIdeaDependencyResolutionTest : AbstractLightweightIdeaDependen
|
||||
module.assertContainsFragment("jvm").assertResolvedBinaryDependencies(
|
||||
CLASSPATH_BINARY_TYPE,
|
||||
"org.jetbrains.kotlin:kotlin-stdlib:${project.getKotlinPluginVersion()}",
|
||||
"org.jetbrains.kotlin:kotlin-stdlib-jdk7:${project.getKotlinPluginVersion()}",
|
||||
"org.jetbrains.kotlin:kotlin-stdlib-jdk8:${project.getKotlinPluginVersion()}",
|
||||
Regex("""org\.jetbrains:annotations:.*"""),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user