[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) {
|
||||
warnAboutKotlin12xMppDeprecation(project)
|
||||
|
||||
val implementConfig = project.configurations.createDependencyScope(IMPLEMENT_CONFIG_NAME)
|
||||
val expectedByConfig = project.configurations.createDependencyScope(EXPECTED_BY_CONFIG_NAME)
|
||||
val implementConfig = project.configurations.createDependencyScope(IMPLEMENT_CONFIG_NAME).get()
|
||||
val expectedByConfig = project.configurations.createDependencyScope(EXPECTED_BY_CONFIG_NAME).get()
|
||||
|
||||
implementConfig.dependencies.whenObjectAdded {
|
||||
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.launchInStage
|
||||
import org.jetbrains.kotlin.gradle.utils.copyAttributesTo
|
||||
import org.jetbrains.kotlin.gradle.utils.createDependencyScope
|
||||
import org.jetbrains.kotlin.gradle.utils.findDependencyScope
|
||||
import org.jetbrains.kotlin.gradle.utils.maybeCreateDependencyScope
|
||||
import org.jetbrains.kotlin.tooling.core.UnsafeApi
|
||||
|
||||
internal fun KotlinTargetSoftwareComponent(
|
||||
@@ -34,20 +33,19 @@ internal fun KotlinTargetSoftwareComponent(
|
||||
/* Explicitly typing 'Project' to avoid smart cast from 'target.project as ProjectInternal' */
|
||||
val project: Project = target.project
|
||||
val publishedConfigurationName = publishedConfigurationName(kotlinUsageContext.name)
|
||||
val configuration = project.configurations.findDependencyScope(publishedConfigurationName)
|
||||
?: project.configurations.createDependencyScope(publishedConfigurationName).also { publishedConfiguration ->
|
||||
publishedConfiguration.isVisible = false
|
||||
publishedConfiguration.extendsFrom(project.configurations.getByName(kotlinUsageContext.dependencyConfigurationName))
|
||||
publishedConfiguration.artifacts.addAll(kotlinUsageContext.artifacts)
|
||||
// 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()`
|
||||
// Test failing without it - KotlinAndroidMppIT#testMppAndroidLibFlavorsPublication
|
||||
kotlinUsageContext.attributes.keySet()
|
||||
kotlinUsageContext.copyAttributesTo(
|
||||
project,
|
||||
dest = publishedConfiguration
|
||||
)
|
||||
}
|
||||
val configuration = project.configurations.maybeCreateDependencyScope(publishedConfigurationName) {
|
||||
isVisible = false
|
||||
extendsFrom(project.configurations.getByName(kotlinUsageContext.dependencyConfigurationName))
|
||||
artifacts.addAll(kotlinUsageContext.artifacts)
|
||||
// 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()`
|
||||
// Test failing without it - KotlinAndroidMppIT#testMppAndroidLibFlavorsPublication
|
||||
kotlinUsageContext.attributes.keySet()
|
||||
kotlinUsageContext.copyAttributesTo(
|
||||
project,
|
||||
dest = this
|
||||
)
|
||||
}
|
||||
|
||||
adhocVariant.addVariantsFromConfiguration(configuration) { configurationVariantDetails ->
|
||||
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"
|
||||
|
||||
fun configureForSourceSet(project: Project, sourceSetName: String) {
|
||||
val discoveryConfiguration = project.configurations.maybeCreateDependencyScope(getDiscoveryClasspathConfigurationName(sourceSetName)).apply {
|
||||
isVisible = false
|
||||
description = "Script filename extensions discovery classpath configuration"
|
||||
}
|
||||
val discoveryConfiguration = project.configurations
|
||||
.maybeCreateDependencyScope(getDiscoveryClasspathConfigurationName(sourceSetName)) {
|
||||
isVisible = false
|
||||
description = "Script filename extensions discovery classpath configuration"
|
||||
}
|
||||
project.logger.info("$SCRIPTING_LOG_PREFIX created the scripting discovery configuration: ${discoveryConfiguration.name}")
|
||||
|
||||
configureDiscoveryTransformation(project, discoveryConfiguration, getDiscoveryResultsConfigurationName(sourceSetName))
|
||||
|
||||
+20
-6
@@ -5,9 +5,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.utils
|
||||
|
||||
import org.gradle.api.NamedDomainObjectProvider
|
||||
import org.gradle.api.artifacts.Configuration
|
||||
import org.gradle.api.artifacts.ConfigurationContainer
|
||||
import org.gradle.api.artifacts.Dependency
|
||||
import org.gradle.util.GradleVersion
|
||||
|
||||
const val COMPILE_ONLY = "compileOnly"
|
||||
const val COMPILE = "compile"
|
||||
@@ -16,6 +18,7 @@ const val API = "api"
|
||||
const val RUNTIME_ONLY = "runtimeOnly"
|
||||
const val RUNTIME = "runtime"
|
||||
internal const val INTRANSITIVE = "intransitive"
|
||||
private val gradleVersionWithNewApi = GradleVersion.version("8.4")
|
||||
|
||||
internal fun ConfigurationContainer.createResolvable(name: String): Configuration = create(name).apply {
|
||||
isCanBeConsumed = false
|
||||
@@ -62,10 +65,19 @@ internal fun ConfigurationContainer.findConsumable(name: String): Configuration?
|
||||
internal fun ConfigurationContainer.maybeCreateConsumable(name: String): Configuration =
|
||||
findConsumable(name) ?: createConsumable(name)
|
||||
|
||||
internal fun ConfigurationContainer.createDependencyScope(name: String) = create(name).apply {
|
||||
isCanBeResolved = false
|
||||
isCanBeConsumed = false
|
||||
}
|
||||
internal fun ConfigurationContainer.createDependencyScope(
|
||||
name: String,
|
||||
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 {
|
||||
if (isCanBeResolved && isCanBeConsumed) {
|
||||
@@ -77,5 +89,7 @@ internal fun ConfigurationContainer.findDependencyScope(name: String): Configura
|
||||
}
|
||||
}
|
||||
|
||||
internal fun ConfigurationContainer.maybeCreateDependencyScope(name: String): Configuration =
|
||||
findDependencyScope(name) ?: createDependencyScope(name)
|
||||
internal fun ConfigurationContainer.maybeCreateDependencyScope(
|
||||
name: String,
|
||||
configurationOnCreate: Configuration.() -> Unit = {}
|
||||
): Configuration = findDependencyScope(name) ?: createDependencyScope(name, configurationOnCreate).get()
|
||||
|
||||
Reference in New Issue
Block a user