[Gradle] Implement CustomizeKotlinDependenciesSetupAction
KT-61634
This commit is contained in:
committed by
Space Team
parent
eba13b5b91
commit
6afe716238
+8
-7
@@ -12,9 +12,10 @@ import org.gradle.api.artifacts.ExternalDependency
|
||||
import org.gradle.api.artifacts.ProjectDependency
|
||||
import org.gradle.api.artifacts.dsl.DependencyHandler
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull
|
||||
import org.jetbrains.kotlin.gradle.dsl.topLevelExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationToRunnableFiles
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinProjectSetupAction
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataTarget
|
||||
@@ -27,25 +28,25 @@ internal const val KOTLIN_COMPILER_EMBEDDABLE = "kotlin-compiler-embeddable"
|
||||
internal const val KOTLIN_BUILD_TOOLS_API_IMPL = "kotlin-build-tools-impl"
|
||||
internal const val PLATFORM_INTEGERS_SUPPORT_LIBRARY = "platform-integers"
|
||||
|
||||
internal fun customizeKotlinDependencies(project: Project) {
|
||||
val topLevelExtension = project.topLevelExtension
|
||||
internal val CustomizeKotlinDependenciesSetupAction = KotlinProjectSetupAction {
|
||||
val kotlinExtension = project.kotlinExtension
|
||||
val propertiesProvider = PropertiesProvider(project)
|
||||
val coreLibrariesVersion = project.objects.providerWithLazyConvention {
|
||||
topLevelExtension.coreLibrariesVersion
|
||||
kotlinExtension.coreLibrariesVersion
|
||||
}
|
||||
|
||||
if (propertiesProvider.stdlibDefaultDependency)
|
||||
project.configureStdlibDefaultDependency(topLevelExtension, coreLibrariesVersion)
|
||||
project.configureStdlibDefaultDependency(kotlinExtension, coreLibrariesVersion)
|
||||
|
||||
if (propertiesProvider.kotlinTestInferJvmVariant) { // TODO: extend this logic to PM20
|
||||
project.configureKotlinTestDependency(
|
||||
topLevelExtension,
|
||||
kotlinExtension,
|
||||
coreLibrariesVersion,
|
||||
)
|
||||
}
|
||||
|
||||
if (propertiesProvider.stdlibDomApiIncluded) {
|
||||
project.configureKotlinDomApiDefaultDependency(topLevelExtension, coreLibrariesVersion)
|
||||
project.configureKotlinDomApiDefaultDependency(kotlinExtension, coreLibrariesVersion)
|
||||
}
|
||||
|
||||
project.configurations.configureDefaultVersionsResolutionStrategy(coreLibrariesVersion)
|
||||
|
||||
+4
-15
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.gradle.plugin.sources.KotlinDependencyScope
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.sourceSetDependencyConfigurationByScope
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.SemVer
|
||||
import org.jetbrains.kotlin.gradle.utils.forAllTargets
|
||||
|
||||
private const val KOTLIN_DOM_API_MODULE_NAME = "kotlin-dom-api-compat"
|
||||
|
||||
@@ -29,23 +30,11 @@ private val kotlin190Version = SemVer(1.toBigInteger(), 9.toBigInteger(), 0.toBi
|
||||
private fun isAtLeast1_9_0(version: String) = SemVer.fromGradleRichVersion(version) >= kotlin190Version
|
||||
|
||||
internal fun Project.configureKotlinDomApiDefaultDependency(
|
||||
topLevelExtension: KotlinTopLevelExtension,
|
||||
kotlinExtension: KotlinProjectExtension,
|
||||
coreLibrariesVersion: Provider<String>
|
||||
) {
|
||||
when (topLevelExtension) {
|
||||
is KotlinJsProjectExtension -> topLevelExtension.registerTargetObserver { target ->
|
||||
target?.addKotlinDomApiDependency(configurations, dependencies, coreLibrariesVersion)
|
||||
}
|
||||
|
||||
is KotlinSingleTargetExtension<*> -> topLevelExtension
|
||||
.target
|
||||
.addKotlinDomApiDependency(configurations, dependencies, coreLibrariesVersion)
|
||||
|
||||
is KotlinMultiplatformExtension -> topLevelExtension
|
||||
.targets
|
||||
.configureEach { target ->
|
||||
target.addKotlinDomApiDependency(configurations, dependencies, coreLibrariesVersion)
|
||||
}
|
||||
kotlinExtension.forAllTargets { target ->
|
||||
target.addKotlinDomApiDependency(configurations, dependencies, coreLibrariesVersion)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
-28
@@ -22,10 +22,7 @@ import org.gradle.api.tasks.testing.Test
|
||||
import org.gradle.api.tasks.testing.junit.JUnitOptions
|
||||
import org.gradle.api.tasks.testing.junitplatform.JUnitPlatformOptions
|
||||
import org.gradle.api.tasks.testing.testng.TestNGOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinSingleTargetExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinTopLevelExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.*
|
||||
import org.jetbrains.kotlin.gradle.execution.KotlinAggregateExecutionSource
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmAndroidCompilation
|
||||
@@ -36,6 +33,7 @@ import org.jetbrains.kotlin.gradle.targets.js.npm.SemVer
|
||||
import org.jetbrains.kotlin.gradle.targets.jvm.JvmCompilationsTestRunSource
|
||||
import org.jetbrains.kotlin.gradle.tasks.locateTask
|
||||
import org.jetbrains.kotlin.gradle.testing.KotlinTaskTestRun
|
||||
import org.jetbrains.kotlin.gradle.utils.forAllTargets
|
||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||
|
||||
private val Dependency.isKotlinTestRootDependency: Boolean
|
||||
@@ -48,34 +46,16 @@ private fun isAtLeast1_5(version: String) = SemVer.fromGradleRichVersion(version
|
||||
private val jvmPlatforms = setOf(KotlinPlatformType.jvm, KotlinPlatformType.androidJvm)
|
||||
|
||||
internal fun Project.configureKotlinTestDependency(
|
||||
topLevelExtension: KotlinTopLevelExtension,
|
||||
kotlinExtension: KotlinProjectExtension,
|
||||
coreLibrariesVersion: Provider<String>,
|
||||
) {
|
||||
when (topLevelExtension) {
|
||||
is KotlinJsProjectExtension -> topLevelExtension.registerTargetObserver { target ->
|
||||
target?.configureKotlinTestDependency(
|
||||
configurations,
|
||||
coreLibrariesVersion,
|
||||
dependencies,
|
||||
tasks
|
||||
)
|
||||
}
|
||||
|
||||
is KotlinSingleTargetExtension<*> -> topLevelExtension.target.configureKotlinTestDependency(
|
||||
kotlinExtension.forAllTargets { target ->
|
||||
target.configureKotlinTestDependency(
|
||||
configurations,
|
||||
coreLibrariesVersion,
|
||||
dependencies,
|
||||
tasks
|
||||
)
|
||||
|
||||
is KotlinMultiplatformExtension -> topLevelExtension.targets.configureEach { target ->
|
||||
target.configureKotlinTestDependency(
|
||||
configurations,
|
||||
coreLibrariesVersion,
|
||||
dependencies,
|
||||
tasks
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +63,7 @@ private fun KotlinTarget.configureKotlinTestDependency(
|
||||
configurations: ConfigurationContainer,
|
||||
coreLibrariesVersion: Provider<String>,
|
||||
dependencyHandler: DependencyHandler,
|
||||
tasks: TaskContainer
|
||||
tasks: TaskContainer,
|
||||
) {
|
||||
compilations.configureEach { compilation ->
|
||||
val platformType = compilation.platformType
|
||||
@@ -121,7 +101,7 @@ private fun Configuration.maybeAddTestDependencyCapability(
|
||||
compilation: KotlinCompilation<*>,
|
||||
coreLibrariesVersion: Provider<String>,
|
||||
dependencyHandler: DependencyHandler,
|
||||
tasks: TaskContainer
|
||||
tasks: TaskContainer,
|
||||
) {
|
||||
withDependencies { dependencies ->
|
||||
val testRootDependency = allNonProjectDependencies()
|
||||
@@ -202,7 +182,7 @@ private fun testFrameworkOf(testTask: Test): KotlinTestJvmFramework = when (test
|
||||
}
|
||||
|
||||
private fun KotlinTargetWithTests<*, *>.findTestRunsByCompilation(
|
||||
byCompilation: KotlinCompilation<*>
|
||||
byCompilation: KotlinCompilation<*>,
|
||||
): NamedDomainObjectSet<out KotlinTargetTestRun<*>> {
|
||||
fun KotlinExecution.ExecutionSource.isProducedFromTheCompilation(): Boolean = when (this) {
|
||||
is CompilationExecutionSource<*> -> compilation == byCompilation
|
||||
|
||||
+9
-25
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.gradle.plugin.sources.sourceSetDependencyConfigurati
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinWasmTargetType
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.SemVer
|
||||
import org.jetbrains.kotlin.gradle.utils.forAllTargets
|
||||
import org.jetbrains.kotlin.gradle.utils.withType
|
||||
|
||||
internal const val KOTLIN_STDLIB_COMMON_MODULE_NAME = "kotlin-stdlib-common"
|
||||
@@ -37,33 +38,16 @@ internal const val KOTLIN_STDLIB_JS_MODULE_NAME = "kotlin-stdlib-js"
|
||||
internal const val KOTLIN_ANDROID_JVM_STDLIB_MODULE_NAME = KOTLIN_STDLIB_MODULE_NAME
|
||||
|
||||
internal fun Project.configureStdlibDefaultDependency(
|
||||
topLevelExtension: KotlinTopLevelExtension,
|
||||
kotlinExtension: KotlinProjectExtension,
|
||||
coreLibrariesVersion: Provider<String>,
|
||||
) {
|
||||
when (topLevelExtension) {
|
||||
is KotlinJsProjectExtension -> topLevelExtension.registerTargetObserver { target ->
|
||||
target?.addStdlibDependency(
|
||||
configurations,
|
||||
dependencies,
|
||||
coreLibrariesVersion,
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
is KotlinSingleTargetExtension<*> -> topLevelExtension
|
||||
.target
|
||||
.addStdlibDependency(
|
||||
configurations,
|
||||
dependencies,
|
||||
coreLibrariesVersion,
|
||||
false
|
||||
)
|
||||
|
||||
is KotlinMultiplatformExtension -> topLevelExtension
|
||||
.targets
|
||||
.configureEach { target ->
|
||||
target.addStdlibDependency(configurations, dependencies, coreLibrariesVersion, true)
|
||||
}
|
||||
kotlinExtension.forAllTargets { target ->
|
||||
target.addStdlibDependency(
|
||||
configurations,
|
||||
dependencies,
|
||||
coreLibrariesVersion,
|
||||
isMppProject = kotlinExtension is KotlinMultiplatformExtension,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-6
@@ -21,7 +21,6 @@ import org.gradle.jvm.tasks.Jar
|
||||
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinSingleJavaTargetExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
||||
import org.jetbrains.kotlin.gradle.internal.customizeKotlinDependencies
|
||||
import org.jetbrains.kotlin.gradle.model.builder.KotlinModelBuilder
|
||||
import org.jetbrains.kotlin.gradle.plugin.internal.JavaSourceSetsAccessor
|
||||
import org.jetbrains.kotlin.gradle.plugin.internal.MavenPluginConfigurator
|
||||
@@ -64,7 +63,6 @@ internal abstract class AbstractKotlinPlugin(
|
||||
|
||||
rewriteMppDependenciesInPom(target)
|
||||
|
||||
configureProjectGlobalSettings(project)
|
||||
configureClassInspectionForIC(project)
|
||||
registry.register(KotlinModelBuilder(kotlinPluginVersion, null))
|
||||
|
||||
@@ -151,10 +149,6 @@ internal abstract class AbstractKotlinPlugin(
|
||||
companion object {
|
||||
private const val INSPECT_IC_CLASSES_TASK_NAME = "inspectClassesForKotlinIC"
|
||||
|
||||
fun configureProjectGlobalSettings(project: Project) {
|
||||
customizeKotlinDependencies(project)
|
||||
}
|
||||
|
||||
fun configureTarget(
|
||||
target: KotlinWithJavaTarget<*, *>,
|
||||
buildSourceSetProcessor: (KotlinCompilation<*>) -> KotlinSourceSetProcessor<*>
|
||||
|
||||
-2
@@ -14,7 +14,6 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
||||
import org.jetbrains.kotlin.gradle.internal.customizeKotlinDependencies
|
||||
import org.jetbrains.kotlin.gradle.model.builder.KotlinModelBuilder
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinJvmPlugin.Companion.configureCompilerOptionsForTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget
|
||||
@@ -54,7 +53,6 @@ internal open class KotlinAndroidPlugin(
|
||||
}
|
||||
}
|
||||
) { androidTarget ->
|
||||
customizeKotlinDependencies(project)
|
||||
registry.register(KotlinModelBuilder(project.getKotlinPluginVersion(), androidTarget))
|
||||
project.whenEvaluated { project.components.addAll(androidTarget.components) }
|
||||
}
|
||||
|
||||
-2
@@ -9,7 +9,6 @@ import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.plugins.JavaBasePlugin
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.internal.customizeKotlinDependencies
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.internal.runDeprecationDiagnostics
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinWasmTargetType
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTargetPreset
|
||||
@@ -28,7 +27,6 @@ class KotlinMultiplatformPlugin : Plugin<Project> {
|
||||
project.plugins.apply(JavaBasePlugin::class.java)
|
||||
|
||||
setupDefaultPresets(project)
|
||||
customizeKotlinDependencies(project)
|
||||
}
|
||||
|
||||
fun setupDefaultPresets(project: Project) {
|
||||
|
||||
+2
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.gradle.dsl.AndroidMainSourceSetConventionsChecker
|
||||
import org.jetbrains.kotlin.gradle.dsl.IosSourceSetConventionChecker
|
||||
import org.jetbrains.kotlin.gradle.dsl.PlatformSourceSetConventionsChecker
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull
|
||||
import org.jetbrains.kotlin.gradle.internal.CustomizeKotlinDependenciesSetupAction
|
||||
import org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinToolingDiagnosticsSetupAction
|
||||
import org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinGradleProjectChecker
|
||||
import org.jetbrains.kotlin.gradle.plugin.diagnostics.checkers.AndroidPluginWithoutAndroidTargetChecker
|
||||
@@ -57,6 +58,7 @@ internal fun Project.registerKotlinPluginExtensions() {
|
||||
register(project, KotlinToolingDiagnosticsSetupAction)
|
||||
register(project, SyncLanguageSettingsWithKotlinExtensionSetupAction)
|
||||
register(project, UserDefinedAttributesSetupAction)
|
||||
register(project, CustomizeKotlinDependenciesSetupAction)
|
||||
|
||||
|
||||
if (isJvm || isMultiplatform) {
|
||||
|
||||
-2
@@ -10,7 +10,6 @@ import org.gradle.api.Project
|
||||
import org.gradle.api.plugins.JavaBasePlugin
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
||||
import org.jetbrains.kotlin.gradle.internal.customizeKotlinDependencies
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.MAIN_COMPILATION_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.TEST_COMPILATION_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.compilerOptions
|
||||
@@ -31,7 +30,6 @@ open class KotlinJsPlugin: Plugin<Project> {
|
||||
project.enableKgpDependencyResolution(isEnabled = false)
|
||||
|
||||
val kotlinExtension = project.kotlinExtension as KotlinJsProjectExtension
|
||||
customizeKotlinDependencies(project)
|
||||
|
||||
kotlinExtension.apply {
|
||||
irPreset = KotlinJsIrSingleTargetPreset(project)
|
||||
|
||||
Reference in New Issue
Block a user