[Gradle] Replace useCompilerVersion by a Provider API property
Now this property acts as the single source of truth of BTA implementation version used in KGP. It allows both read and write. ^KT-62921 Fixed
This commit is contained in:
committed by
Space Team
parent
10cedd495d
commit
a904ded5f2
+1
-1
@@ -159,7 +159,7 @@ private fun TestProject.enableOtherVersionBuildToolsImpl() {
|
|||||||
buildGradle.append(
|
buildGradle.append(
|
||||||
"""
|
"""
|
||||||
kotlin {
|
kotlin {
|
||||||
useCompilerVersion("$OTHER_KOTLIN_VERSION")
|
compilerVersion.set("$OTHER_KOTLIN_VERSION")
|
||||||
}
|
}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
|
|||||||
+17
-10
@@ -10,12 +10,11 @@ import org.gradle.api.Named
|
|||||||
import org.gradle.api.NamedDomainObjectContainer
|
import org.gradle.api.NamedDomainObjectContainer
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.internal.plugins.DslObject
|
import org.gradle.api.internal.plugins.DslObject
|
||||||
|
import org.gradle.api.provider.Property
|
||||||
import org.gradle.jvm.toolchain.JavaLanguageVersion
|
import org.gradle.jvm.toolchain.JavaLanguageVersion
|
||||||
import org.gradle.jvm.toolchain.JavaToolchainSpec
|
import org.gradle.jvm.toolchain.JavaToolchainSpec
|
||||||
import org.jetbrains.kotlin.buildtools.api.ExperimentalBuildToolsApi
|
import org.jetbrains.kotlin.buildtools.api.ExperimentalBuildToolsApi
|
||||||
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
|
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
|
||||||
import org.jetbrains.kotlin.gradle.internal.KOTLIN_BUILD_TOOLS_API_IMPL
|
|
||||||
import org.jetbrains.kotlin.gradle.internal.KOTLIN_MODULE_GROUP
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.*
|
import org.jetbrains.kotlin.gradle.plugin.*
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginLifecycle.CoroutineStart.Undispatched
|
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginLifecycle.CoroutineStart.Undispatched
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
|
||||||
@@ -139,18 +138,26 @@ abstract class KotlinTopLevelExtension(internal val project: Project) : KotlinTo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Deprecated("This method is replaced by the `compilerVersion` property", ReplaceWith("compilerVersion"), DeprecationLevel.ERROR)
|
||||||
* Allows to use a different version of the Kotlin Build Tools API implementation and effectively a different version of the compiler.
|
|
||||||
*
|
|
||||||
* By default, the Kotlin Build Tools API implementation of the same version as the KGP is used.
|
|
||||||
*
|
|
||||||
* Currently only has an effect if the `kotlin.compiler.runViaBuildToolsApi` Gradle property is set to `true`.
|
|
||||||
*/
|
|
||||||
@ExperimentalKotlinGradlePluginApi
|
@ExperimentalKotlinGradlePluginApi
|
||||||
@ExperimentalBuildToolsApi
|
@ExperimentalBuildToolsApi
|
||||||
fun useCompilerVersion(version: String) {
|
fun useCompilerVersion(version: String) {
|
||||||
project.dependencies.add(BUILD_TOOLS_API_CLASSPATH_CONFIGURATION_NAME, "$KOTLIN_MODULE_GROUP:$KOTLIN_BUILD_TOOLS_API_IMPL:$version")
|
compilerVersion.set(version)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The version of the Kotlin compiler.
|
||||||
|
*
|
||||||
|
* By default, the Kotlin Build Tools API implementation of the same version as the KGP is used.
|
||||||
|
*
|
||||||
|
* Be careful with reading the property's value as eager reading will finalize the value and prevent it from being configured.
|
||||||
|
*
|
||||||
|
* Note: Currently only has an effect if the `kotlin.compiler.runViaBuildToolsApi` Gradle property is set to `true`.
|
||||||
|
*/
|
||||||
|
@ExperimentalKotlinGradlePluginApi
|
||||||
|
@ExperimentalBuildToolsApi
|
||||||
|
val compilerVersion: Property<String> =
|
||||||
|
project.objects.propertyWithConvention(project.getKotlinPluginVersion()).chainedFinalizeValueOnRead()
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun ExplicitApiMode.toCompilerValue() = when (this) {
|
internal fun ExplicitApiMode.toCompilerValue() = when (this) {
|
||||||
|
|||||||
+12
-4
@@ -20,6 +20,7 @@ import org.gradle.api.GradleException
|
|||||||
import org.gradle.api.NamedDomainObjectFactory
|
import org.gradle.api.NamedDomainObjectFactory
|
||||||
import org.gradle.api.Plugin
|
import org.gradle.api.Plugin
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.artifacts.ExternalDependency
|
||||||
import org.gradle.api.logging.Logger
|
import org.gradle.api.logging.Logger
|
||||||
import org.gradle.api.logging.Logging
|
import org.gradle.api.logging.Logging
|
||||||
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
|
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
|
||||||
@@ -102,10 +103,17 @@ abstract class DefaultKotlinBasePlugin : KotlinBasePlugin {
|
|||||||
project
|
project
|
||||||
.configurations
|
.configurations
|
||||||
.maybeCreateResolvable(BUILD_TOOLS_API_CLASSPATH_CONFIGURATION_NAME)
|
.maybeCreateResolvable(BUILD_TOOLS_API_CLASSPATH_CONFIGURATION_NAME)
|
||||||
.defaultDependencies {
|
.also {
|
||||||
it.add(
|
project.dependencies.add(it.name, "$KOTLIN_MODULE_GROUP:$KOTLIN_BUILD_TOOLS_API_IMPL")
|
||||||
project.dependencies.create("$KOTLIN_MODULE_GROUP:$KOTLIN_BUILD_TOOLS_API_IMPL:${project.getKotlinPluginVersion()}")
|
it.withDependencies { dependencies ->
|
||||||
)
|
dependencies
|
||||||
|
.withType<ExternalDependency>()
|
||||||
|
.configureEach { dependency ->
|
||||||
|
dependency.version { versionConstraint ->
|
||||||
|
versionConstraint.strictly(project.kotlinExtension.compilerVersion.get())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
project
|
project
|
||||||
.tasks
|
.tasks
|
||||||
|
|||||||
Reference in New Issue
Block a user