From 1b0ab7dbc1cbe91df8f8952c55826f07359d203f Mon Sep 17 00:00:00 2001 From: Anton Lakotka Date: Thu, 4 Jul 2024 17:05:55 +0200 Subject: [PATCH] [Gradle] Add archivesTaskOutputAsFriendModule flag This flag should disable redundant logic in Friends Artifacts Reolver that adds Kotlin Target's archive file as a friend path to associated compialtions. It should be enough to just use compiler outputs. But this change requires proper migration. Enable this flag for kotlin-stdlib as it's associated compilations contribute to archives task. This should break cyclic dependency. ^KT-58280 --- libraries/stdlib/gradle.properties | 3 ++- .../org/jetbrains/kotlin/gradle/plugin/PropertiesProvider.kt | 4 ++++ .../compilationImpl/KotlinCompilationFriendPathsResolver.kt | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libraries/stdlib/gradle.properties b/libraries/stdlib/gradle.properties index 49005b4378647..7ac86c2a54662 100644 --- a/libraries/stdlib/gradle.properties +++ b/libraries/stdlib/gradle.properties @@ -1,3 +1,4 @@ kotlin.internal.suppressGradlePluginErrors=PreHMPPFlagsError kotlin.mpp.enableCompatibilityMetadataVariant=true -kotlin.internal.mpp.createDefaultMultiplatformPublications=false \ No newline at end of file +kotlin.internal.mpp.createDefaultMultiplatformPublications=false +kotlin.internal.archivesTaskOutputAsFriendModule=false \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/PropertiesProvider.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/PropertiesProvider.kt index e69ba0b56b5ad..05974d1be63d2 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/PropertiesProvider.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/PropertiesProvider.kt @@ -601,6 +601,9 @@ internal class PropertiesProvider private constructor(private val project: Proje val enableFusMetricsCollection: Boolean get() = booleanProperty(PropertyNames.KOTLIN_COLLECT_FUS_METRICS_ENABLED) ?: true + val archivesTaskOutputAsFriendModule: Boolean + get() = booleanProperty(PropertyNames.KOTLIN_ARCHIVES_TASK_OUTPUT_AS_FRIEND_ENABLED) ?: true + /** * Retrieves a comma-separated list of browsers to use when running karma tests for [target] * @see KOTLIN_JS_KARMA_BROWSERS @@ -725,6 +728,7 @@ internal class PropertiesProvider private constructor(private val project: Proje property("$KOTLIN_INTERNAL_NAMESPACE.incremental.enableUnsafeOptimizationsForMultiplatform") val KOTLIN_KLIBS_KT64115_WORKAROUND_ENABLED = property("$KOTLIN_INTERNAL_NAMESPACE.klibs.enableWorkaroundForKT64115") val KOTLIN_COLLECT_FUS_METRICS_ENABLED = property("$KOTLIN_INTERNAL_NAMESPACE.collectFUSMetrics") + val KOTLIN_ARCHIVES_TASK_OUTPUT_AS_FRIEND_ENABLED = property("$KOTLIN_INTERNAL_NAMESPACE.archivesTaskOutputAsFriendModule") } companion object { diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/compilationImpl/KotlinCompilationFriendPathsResolver.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/compilationImpl/KotlinCompilationFriendPathsResolver.kt index ffc76b20697ca..ba2892bc8b31d 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/compilationImpl/KotlinCompilationFriendPathsResolver.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/compilationImpl/KotlinCompilationFriendPathsResolver.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl import org.gradle.api.file.FileCollection import org.gradle.api.tasks.TaskProvider import org.gradle.api.tasks.bundling.AbstractArchiveTask +import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.Companion.kotlinPropertiesProvider import org.jetbrains.kotlin.gradle.plugin.mpp.* import org.jetbrains.kotlin.gradle.plugin.sources.getVisibleSourceSetsFromAssociateCompilations import org.jetbrains.kotlin.gradle.tasks.KotlinCompileTool @@ -61,6 +62,8 @@ internal class DefaultKotlinCompilationFriendPathsResolver( object DefaultFriendArtifactResolver : FriendArtifactResolver { override fun resolveFriendArtifacts(compilation: InternalKotlinCompilation<*>): FileCollection { + if (!compilation.project.kotlinPropertiesProvider.archivesTaskOutputAsFriendModule) return compilation.project.files() + return with(compilation.project) { val friendArtifactsTaskProvider = resolveFriendArtifactsTask(compilation) ?: return files() filesProvider { friendArtifactsTaskProvider.flatMap { it.archiveFile } }