[Gradle] Use specialized 'dependencyScope' configuration container
Gradle 8.4 has introduced a new set of APIs: https://docs.gradle.org/8.4/release-notes.html#easier-to-create-role-focused-configurations We this change we started to create a 'DependencyScopeConfiguration' for configurations used to declare dependencies. ^KT-65143 In Progress
This commit is contained in:
committed by
Space Team
parent
be1819da58
commit
fcfc2446cf
+2
-2
@@ -54,8 +54,8 @@ open class KotlinPlatformImplementationPluginBase(platformName: String) : Kotlin
|
|||||||
override fun apply(project: Project) {
|
override fun apply(project: Project) {
|
||||||
warnAboutKotlin12xMppDeprecation(project)
|
warnAboutKotlin12xMppDeprecation(project)
|
||||||
|
|
||||||
val implementConfig = project.configurations.createDependencyScope(IMPLEMENT_CONFIG_NAME)
|
val implementConfig = project.configurations.createDependencyScope(IMPLEMENT_CONFIG_NAME).get()
|
||||||
val expectedByConfig = project.configurations.createDependencyScope(EXPECTED_BY_CONFIG_NAME)
|
val expectedByConfig = project.configurations.createDependencyScope(EXPECTED_BY_CONFIG_NAME).get()
|
||||||
|
|
||||||
implementConfig.dependencies.whenObjectAdded {
|
implementConfig.dependencies.whenObjectAdded {
|
||||||
if (!implementConfigurationIsUsed) {
|
if (!implementConfigurationIsUsed) {
|
||||||
|
|||||||
+14
-16
@@ -17,8 +17,7 @@ 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.copyAttributesTo
|
import org.jetbrains.kotlin.gradle.utils.copyAttributesTo
|
||||||
import org.jetbrains.kotlin.gradle.utils.createDependencyScope
|
import org.jetbrains.kotlin.gradle.utils.maybeCreateDependencyScope
|
||||||
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(
|
||||||
@@ -34,20 +33,19 @@ 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.findDependencyScope(publishedConfigurationName)
|
val configuration = project.configurations.maybeCreateDependencyScope(publishedConfigurationName) {
|
||||||
?: project.configurations.createDependencyScope(publishedConfigurationName).also { publishedConfiguration ->
|
isVisible = false
|
||||||
publishedConfiguration.isVisible = false
|
extendsFrom(project.configurations.getByName(kotlinUsageContext.dependencyConfigurationName))
|
||||||
publishedConfiguration.extendsFrom(project.configurations.getByName(kotlinUsageContext.dependencyConfigurationName))
|
artifacts.addAll(kotlinUsageContext.artifacts)
|
||||||
publishedConfiguration.artifacts.addAll(kotlinUsageContext.artifacts)
|
// KT-64789: workaround for missing 'org.gradle.libraryelements' attribute on the kotlinUsageContext returned keys Set
|
||||||
// KT-64789: workaround for missing 'org.gradle.libraryelements' attribute on the kotlinUsageContext returned keys Set
|
// So far I don't know the reason why it appears only on the second call to `keySet()`
|
||||||
// So far I don't know the reason why it appears only on the second call to `keySet()`
|
// Test failing without it - KotlinAndroidMppIT#testMppAndroidLibFlavorsPublication
|
||||||
// Test failing without it - KotlinAndroidMppIT#testMppAndroidLibFlavorsPublication
|
kotlinUsageContext.attributes.keySet()
|
||||||
kotlinUsageContext.attributes.keySet()
|
kotlinUsageContext.copyAttributesTo(
|
||||||
kotlinUsageContext.copyAttributesTo(
|
project,
|
||||||
project,
|
dest = this
|
||||||
dest = publishedConfiguration
|
)
|
||||||
)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
adhocVariant.addVariantsFromConfiguration(configuration) { configurationVariantDetails ->
|
adhocVariant.addVariantsFromConfiguration(configuration) { configurationVariantDetails ->
|
||||||
val mavenScope = kotlinUsageContext.mavenScope
|
val mavenScope = kotlinUsageContext.mavenScope
|
||||||
|
|||||||
+5
-4
@@ -44,10 +44,11 @@ class ScriptingGradleSubplugin : Plugin<Project> {
|
|||||||
const val MISCONFIGURATION_MESSAGE_SUFFIX = "the plugin is probably applied by a mistake"
|
const val MISCONFIGURATION_MESSAGE_SUFFIX = "the plugin is probably applied by a mistake"
|
||||||
|
|
||||||
fun configureForSourceSet(project: Project, sourceSetName: String) {
|
fun configureForSourceSet(project: Project, sourceSetName: String) {
|
||||||
val discoveryConfiguration = project.configurations.maybeCreateDependencyScope(getDiscoveryClasspathConfigurationName(sourceSetName)).apply {
|
val discoveryConfiguration = project.configurations
|
||||||
isVisible = false
|
.maybeCreateDependencyScope(getDiscoveryClasspathConfigurationName(sourceSetName)) {
|
||||||
description = "Script filename extensions discovery classpath configuration"
|
isVisible = false
|
||||||
}
|
description = "Script filename extensions discovery classpath configuration"
|
||||||
|
}
|
||||||
project.logger.info("$SCRIPTING_LOG_PREFIX created the scripting discovery configuration: ${discoveryConfiguration.name}")
|
project.logger.info("$SCRIPTING_LOG_PREFIX created the scripting discovery configuration: ${discoveryConfiguration.name}")
|
||||||
|
|
||||||
configureDiscoveryTransformation(project, discoveryConfiguration, getDiscoveryResultsConfigurationName(sourceSetName))
|
configureDiscoveryTransformation(project, discoveryConfiguration, getDiscoveryResultsConfigurationName(sourceSetName))
|
||||||
|
|||||||
+20
-6
@@ -5,9 +5,11 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.utils
|
package org.jetbrains.kotlin.gradle.utils
|
||||||
|
|
||||||
|
import org.gradle.api.NamedDomainObjectProvider
|
||||||
import org.gradle.api.artifacts.Configuration
|
import org.gradle.api.artifacts.Configuration
|
||||||
import org.gradle.api.artifacts.ConfigurationContainer
|
import org.gradle.api.artifacts.ConfigurationContainer
|
||||||
import org.gradle.api.artifacts.Dependency
|
import org.gradle.api.artifacts.Dependency
|
||||||
|
import org.gradle.util.GradleVersion
|
||||||
|
|
||||||
const val COMPILE_ONLY = "compileOnly"
|
const val COMPILE_ONLY = "compileOnly"
|
||||||
const val COMPILE = "compile"
|
const val COMPILE = "compile"
|
||||||
@@ -16,6 +18,7 @@ const val API = "api"
|
|||||||
const val RUNTIME_ONLY = "runtimeOnly"
|
const val RUNTIME_ONLY = "runtimeOnly"
|
||||||
const val RUNTIME = "runtime"
|
const val RUNTIME = "runtime"
|
||||||
internal const val INTRANSITIVE = "intransitive"
|
internal const val INTRANSITIVE = "intransitive"
|
||||||
|
private val gradleVersionWithNewApi = GradleVersion.version("8.4")
|
||||||
|
|
||||||
internal fun ConfigurationContainer.createResolvable(name: String): Configuration = create(name).apply {
|
internal fun ConfigurationContainer.createResolvable(name: String): Configuration = create(name).apply {
|
||||||
isCanBeConsumed = false
|
isCanBeConsumed = false
|
||||||
@@ -62,10 +65,19 @@ internal fun ConfigurationContainer.findConsumable(name: String): Configuration?
|
|||||||
internal fun ConfigurationContainer.maybeCreateConsumable(name: String): Configuration =
|
internal fun ConfigurationContainer.maybeCreateConsumable(name: String): Configuration =
|
||||||
findConsumable(name) ?: createConsumable(name)
|
findConsumable(name) ?: createConsumable(name)
|
||||||
|
|
||||||
internal fun ConfigurationContainer.createDependencyScope(name: String) = create(name).apply {
|
internal fun ConfigurationContainer.createDependencyScope(
|
||||||
isCanBeResolved = false
|
name: String,
|
||||||
isCanBeConsumed = false
|
configuration: Configuration.() -> Unit = {}
|
||||||
}
|
): NamedDomainObjectProvider<out Configuration> =
|
||||||
|
if (GradleVersion.current() >= gradleVersionWithNewApi) {
|
||||||
|
dependencyScope(name, configuration)
|
||||||
|
} else {
|
||||||
|
register(name) {
|
||||||
|
it.isCanBeResolved = false
|
||||||
|
it.isCanBeConsumed = false
|
||||||
|
configuration(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal fun ConfigurationContainer.findDependencyScope(name: String): Configuration? = findByName(name)?.apply {
|
internal fun ConfigurationContainer.findDependencyScope(name: String): Configuration? = findByName(name)?.apply {
|
||||||
if (isCanBeResolved && isCanBeConsumed) {
|
if (isCanBeResolved && isCanBeConsumed) {
|
||||||
@@ -77,5 +89,7 @@ internal fun ConfigurationContainer.findDependencyScope(name: String): Configura
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun ConfigurationContainer.maybeCreateDependencyScope(name: String): Configuration =
|
internal fun ConfigurationContainer.maybeCreateDependencyScope(
|
||||||
findDependencyScope(name) ?: createDependencyScope(name)
|
name: String,
|
||||||
|
configurationOnCreate: Configuration.() -> Unit = {}
|
||||||
|
): Configuration = findDependencyScope(name) ?: createDependencyScope(name, configurationOnCreate).get()
|
||||||
|
|||||||
Reference in New Issue
Block a user