[Gradle] Keep "-publishable" configurations as dependencyScope

As they would clash with the ones that is intended to be consumed as
project dependencies. It will not be compatible with future Gradle
versions. This should be fixed with KT-49919

^KT-60879
This commit is contained in:
Anton Lakotka
2023-11-10 13:12:26 +01:00
parent e73441843b
commit 7673434ccd
2 changed files with 12 additions and 7 deletions
@@ -17,6 +17,8 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinPluginLifecycle
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetComponent import org.jetbrains.kotlin.gradle.plugin.KotlinTargetComponent
import org.jetbrains.kotlin.gradle.plugin.launchInStage import org.jetbrains.kotlin.gradle.plugin.launchInStage
import org.jetbrains.kotlin.gradle.utils.copyAttributes import org.jetbrains.kotlin.gradle.utils.copyAttributes
import org.jetbrains.kotlin.gradle.utils.createDependencyScope
import org.jetbrains.kotlin.gradle.utils.findDependencyScope
import org.jetbrains.kotlin.tooling.core.UnsafeApi import org.jetbrains.kotlin.tooling.core.UnsafeApi
internal fun KotlinTargetSoftwareComponent( internal fun KotlinTargetSoftwareComponent(
@@ -32,10 +34,9 @@ internal fun KotlinTargetSoftwareComponent(
/* Explicitly typing 'Project' to avoid smart cast from 'target.project as ProjectInternal' */ /* Explicitly typing 'Project' to avoid smart cast from 'target.project as ProjectInternal' */
val project: Project = target.project val project: Project = target.project
val publishedConfigurationName = publishedConfigurationName(kotlinUsageContext.name) val publishedConfigurationName = publishedConfigurationName(kotlinUsageContext.name)
val configuration = project.configurations.findByName(publishedConfigurationName) val configuration = project.configurations.findDependencyScope(publishedConfigurationName)
?: project.configurations.create(publishedConfigurationName).also { publishedConfiguration -> ?: project.configurations.createDependencyScope(publishedConfigurationName).also { publishedConfiguration ->
publishedConfiguration.isCanBeConsumed = false publishedConfiguration.isVisible = false
publishedConfiguration.isCanBeResolved = false
publishedConfiguration.extendsFrom(project.configurations.getByName(kotlinUsageContext.dependencyConfigurationName)) publishedConfiguration.extendsFrom(project.configurations.getByName(kotlinUsageContext.dependencyConfigurationName))
publishedConfiguration.artifacts.addAll(kotlinUsageContext.artifacts) publishedConfiguration.artifacts.addAll(kotlinUsageContext.artifacts)
copyAttributes(from = kotlinUsageContext.attributes, to = publishedConfiguration.attributes) copyAttributes(from = kotlinUsageContext.attributes, to = publishedConfiguration.attributes)
@@ -46,14 +46,18 @@ fun <T : DecoratedExternalKotlinTarget> KotlinMultiplatformExtension.createExter
val sourcesElementsConfiguration = project.configurations val sourcesElementsConfiguration = project.configurations
.maybeCreateConsumable(lowerCamelCaseName(descriptor.targetName, "sourcesElements")) .maybeCreateConsumable(lowerCamelCaseName(descriptor.targetName, "sourcesElements"))
fun Configuration.notVisible() = apply { isVisible = false }
val apiElementsPublishedConfiguration = project.configurations val apiElementsPublishedConfiguration = project.configurations
.maybeCreateConsumable(lowerCamelCaseName(descriptor.targetName, "apiElements-published")) .maybeCreateDependencyScope(lowerCamelCaseName(descriptor.targetName, "apiElements-published"))
.notVisible()
val runtimeElementsPublishedConfiguration = project.configurations val runtimeElementsPublishedConfiguration = project.configurations
.maybeCreateConsumable(lowerCamelCaseName(descriptor.targetName, "runtimeElements-published")) .maybeCreateDependencyScope(lowerCamelCaseName(descriptor.targetName, "runtimeElements-published"))
.notVisible()
val sourcesElementsPublishedConfiguration = project.configurations val sourcesElementsPublishedConfiguration = project.configurations
.maybeCreateConsumable(lowerCamelCaseName(descriptor.targetName, "sourcesElements-published")) .maybeCreateDependencyScope(lowerCamelCaseName(descriptor.targetName, "sourcesElements-published"))
.notVisible()
val kotlinTargetComponent = ExternalKotlinTargetComponent( val kotlinTargetComponent = ExternalKotlinTargetComponent(
ExternalKotlinTargetComponent.TargetProvider.byTargetName(this, descriptor.targetName) ExternalKotlinTargetComponent.TargetProvider.byTargetName(this, descriptor.targetName)