[Gradle] Deprecate scoped metadata dependencies
Scoped metadata dependencies are not needed since metadata dependencies are used only for metadata compilation. Metadata is not consumed at runtime. Therefore, scoped metadata dependencies are not required. ^KT-55312
This commit is contained in:
committed by
Space Team
parent
417fef0d58
commit
35b2672436
+5
-6
@@ -25,19 +25,18 @@ interface KotlinSourceSet : Named, HasKotlinDependencies {
|
||||
fun dependsOn(other: KotlinSourceSet)
|
||||
val dependsOn: Set<KotlinSourceSet>
|
||||
|
||||
val metadataLibrariesConfigurationName: String
|
||||
@Deprecated(message = "KT-55312")
|
||||
val apiMetadataConfigurationName: String
|
||||
@Deprecated(message = "KT-55312")
|
||||
val implementationMetadataConfigurationName: String
|
||||
@Deprecated(message = "KT-55312")
|
||||
val compileOnlyMetadataConfigurationName: String
|
||||
@Deprecated(message = "KT-55230: RuntimeOnly scope is not supported for metadata dependency transformation")
|
||||
val runtimeOnlyMetadataConfigurationName: String
|
||||
|
||||
override val relatedConfigurationNames: List<String>
|
||||
get() = super.relatedConfigurationNames +
|
||||
listOf(
|
||||
apiMetadataConfigurationName,
|
||||
implementationMetadataConfigurationName,
|
||||
compileOnlyMetadataConfigurationName,
|
||||
)
|
||||
get() = super.relatedConfigurationNames + metadataLibrariesConfigurationName
|
||||
|
||||
companion object {
|
||||
const val COMMON_MAIN_SOURCE_SET_NAME = "commonMain"
|
||||
|
||||
+1
-2
@@ -86,8 +86,7 @@ private fun KotlinTarget.excludeStdlibAndKotlinTestCommonFromPlatformCompilation
|
||||
compilations.all {
|
||||
listOfNotNull(
|
||||
it.compileDependencyConfigurationName,
|
||||
it.defaultSourceSet.apiMetadataConfigurationName,
|
||||
it.defaultSourceSet.implementationMetadataConfigurationName,
|
||||
it.defaultSourceSet.metadataLibrariesConfigurationName,
|
||||
(it as? KotlinCompilationToRunnableFiles<*>)?.runtimeDependencyConfigurationName,
|
||||
|
||||
// Additional configurations for (old) jvmWithJava-preset. Remove it when we drop it completely
|
||||
|
||||
-9
@@ -97,17 +97,9 @@ internal sealed class MetadataDependencyResolution(
|
||||
internal class GranularMetadataTransformation(
|
||||
val project: Project,
|
||||
val kotlinSourceSet: KotlinSourceSet,
|
||||
/** A list of scopes that the dependencies from [kotlinSourceSet] are treated as requested dependencies. */
|
||||
private val sourceSetRequestedScopes: List<KotlinDependencyScope>,
|
||||
/** A configuration that holds the dependencies of the appropriate scope for all Kotlin source sets in the project */
|
||||
private val parentTransformations: Lazy<Iterable<GranularMetadataTransformation>>
|
||||
) {
|
||||
init {
|
||||
require(KotlinDependencyScope.RUNTIME_ONLY_SCOPE !in sourceSetRequestedScopes) {
|
||||
"KT-55230: RuntimeOnly scope is not supported for metadata dependency transformation"
|
||||
}
|
||||
}
|
||||
|
||||
val metadataDependencyResolutions: Iterable<MetadataDependencyResolution> by lazy { doTransform() }
|
||||
|
||||
// Keep parents of each dependency, too. We need a dependency's parent when it's an MPP's metadata module dependency:
|
||||
@@ -232,7 +224,6 @@ internal class GranularMetadataTransformation(
|
||||
val sourceSetVisibility =
|
||||
SourceSetVisibilityProvider(project).getVisibleSourceSets(
|
||||
kotlinSourceSet,
|
||||
sourceSetRequestedScopes,
|
||||
if (projectStructureMetadata.isPublishedAsRoot) module else parent, module,
|
||||
projectStructureMetadata,
|
||||
resolvedToProject
|
||||
|
||||
-1
@@ -89,7 +89,6 @@ open class MetadataDependencyTransformationTask
|
||||
GranularMetadataTransformation(
|
||||
project,
|
||||
kotlinSourceSet,
|
||||
KotlinDependencyScope.compileScopes,
|
||||
lazy {
|
||||
dependsOnClosureWithInterCompilationDependencies(kotlinSourceSet).map {
|
||||
project.tasks.withType(MetadataDependencyTransformationTask::class.java)
|
||||
|
||||
+1
-21
@@ -49,7 +49,6 @@ internal class SourceSetVisibilityProvider(
|
||||
*/
|
||||
fun getVisibleSourceSets(
|
||||
visibleFrom: KotlinSourceSet,
|
||||
dependencyScopes: Iterable<KotlinDependencyScope>,
|
||||
resolvedRootMppDependency: ResolvedComponentResult?,
|
||||
resolvedMetadataDependency: ResolvedComponentResult,
|
||||
dependencyProjectStructureMetadata: KotlinProjectStructureMetadata,
|
||||
@@ -65,11 +64,7 @@ internal class SourceSetVisibilityProvider(
|
||||
val visiblePlatformVariantNames: Set<String?> =
|
||||
compilations
|
||||
.filter { it.target.platformType != KotlinPlatformType.common }
|
||||
.flatMapTo(mutableSetOf()) { compilation ->
|
||||
// To find out which variant the MPP dependency got resolved for each compilation, take the resolvable configurations
|
||||
// that we have in the compilations:
|
||||
dependencyScopes.mapNotNull { scope -> project.resolvableConfigurationFromCompilationByScope(compilation, scope) }
|
||||
}
|
||||
.map { compilation -> project.configurations.getByName(compilation.compileDependencyConfigurationName) }
|
||||
.mapTo(mutableSetOf()) { configuration ->
|
||||
val resolvedVariant = resolvedVariantsProvider.getResolvedVariantName(mppModuleIdentifier, configuration)
|
||||
?.let { kotlinVariantNameFromPublishedVariantName(it) }
|
||||
@@ -128,18 +123,3 @@ internal class SourceSetVisibilityProvider(
|
||||
|
||||
internal fun kotlinVariantNameFromPublishedVariantName(resolvedToVariantName: String): String =
|
||||
originalVariantNameFromPublished(resolvedToVariantName) ?: resolvedToVariantName
|
||||
|
||||
private fun Project.resolvableConfigurationFromCompilationByScope(
|
||||
compilation: KotlinCompilation<*>,
|
||||
scope: KotlinDependencyScope
|
||||
): Configuration? {
|
||||
val configurationName = when (scope) {
|
||||
KotlinDependencyScope.API_SCOPE, KotlinDependencyScope.IMPLEMENTATION_SCOPE, KotlinDependencyScope.COMPILE_ONLY_SCOPE -> compilation.compileDependencyConfigurationName
|
||||
|
||||
KotlinDependencyScope.RUNTIME_ONLY_SCOPE ->
|
||||
(compilation as? KotlinCompilationToRunnableFiles<*>)?.runtimeDependencyConfigurationName
|
||||
?: return null
|
||||
}
|
||||
|
||||
return project.configurations.getByName(configurationName)
|
||||
}
|
||||
|
||||
+6
@@ -45,12 +45,18 @@ abstract class DefaultKotlinSourceSet @Inject constructor(
|
||||
override val runtimeOnlyConfigurationName: String
|
||||
get() = disambiguateName(RUNTIME_ONLY)
|
||||
|
||||
override val metadataLibrariesConfigurationName: String
|
||||
get() = disambiguateName(lowerCamelCaseName("compile", METADATA_CONFIGURATION_NAME_SUFFIX))
|
||||
|
||||
@Deprecated("KT-55312")
|
||||
override val apiMetadataConfigurationName: String
|
||||
get() = lowerCamelCaseName(apiConfigurationName, METADATA_CONFIGURATION_NAME_SUFFIX)
|
||||
|
||||
@Deprecated("KT-55312")
|
||||
override val implementationMetadataConfigurationName: String
|
||||
get() = lowerCamelCaseName(implementationConfigurationName, METADATA_CONFIGURATION_NAME_SUFFIX)
|
||||
|
||||
@Deprecated("KT-55312")
|
||||
override val compileOnlyMetadataConfigurationName: String
|
||||
get() = lowerCamelCaseName(compileOnlyConfigurationName, METADATA_CONFIGURATION_NAME_SUFFIX)
|
||||
|
||||
|
||||
+1
-11
@@ -51,14 +51,4 @@ internal fun Project.compilationDependencyConfigurationByScope(
|
||||
COMPILE_ONLY_SCOPE -> compilation.compileOnlyConfigurationName
|
||||
RUNTIME_ONLY_SCOPE -> compilation.runtimeOnlyConfigurationName
|
||||
}
|
||||
)
|
||||
|
||||
internal fun Project.sourceSetMetadataConfigurationByScope(sourceSet: KotlinSourceSet, scope: KotlinDependencyScope): Configuration? {
|
||||
val configurationName = when (scope) {
|
||||
API_SCOPE -> sourceSet.apiMetadataConfigurationName
|
||||
IMPLEMENTATION_SCOPE -> sourceSet.implementationMetadataConfigurationName
|
||||
COMPILE_ONLY_SCOPE -> sourceSet.compileOnlyMetadataConfigurationName
|
||||
RUNTIME_ONLY_SCOPE -> return null // KT-55230: RuntimeOnly scope is not supported for metadata dependency transformation
|
||||
}
|
||||
return project.configurations.getByName(configurationName)
|
||||
}
|
||||
)
|
||||
+7
-6
@@ -76,23 +76,24 @@ internal class DefaultKotlinSourceSetFactory(
|
||||
|
||||
val dependencyConfigurationWithMetadata = with(sourceSet) {
|
||||
listOf(
|
||||
apiConfigurationName to apiMetadataConfigurationName,
|
||||
implementationConfigurationName to implementationMetadataConfigurationName,
|
||||
compileOnlyConfigurationName to compileOnlyMetadataConfigurationName,
|
||||
listOf(apiConfigurationName, implementationConfigurationName, compileOnlyConfigurationName) to metadataLibrariesConfigurationName,
|
||||
null to intransitiveMetadataConfigurationName
|
||||
)
|
||||
}
|
||||
|
||||
dependencyConfigurationWithMetadata.forEach { (configurationName, metadataName) ->
|
||||
dependencyConfigurationWithMetadata.forEach { (configurationNames, metadataName) ->
|
||||
project.configurations.maybeCreate(metadataName).apply {
|
||||
attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.common)
|
||||
attributes.attribute(Usage.USAGE_ATTRIBUTE, project.usageByName(KotlinUsages.KOTLIN_API))
|
||||
attributes.attribute(Category.CATEGORY_ATTRIBUTE, project.categoryByName(Category.LIBRARY))
|
||||
isVisible = false
|
||||
isCanBeConsumed = false
|
||||
isCanBeResolved = true
|
||||
|
||||
if (configurationName != null) {
|
||||
extendsFrom(project.configurations.maybeCreate(configurationName))
|
||||
if (configurationNames != null) {
|
||||
for (configurationName in configurationNames) {
|
||||
extendsFrom(project.configurations.maybeCreate(configurationName))
|
||||
}
|
||||
}
|
||||
|
||||
if (project.isKotlinGranularMetadataEnabled) {
|
||||
|
||||
+17
-11
@@ -345,7 +345,7 @@ class KotlinMetadataTargetConfigurator :
|
||||
}
|
||||
|
||||
compilation.compileDependencyFiles += createMetadataDependencyTransformationClasspath(
|
||||
project.configurations.getByName(ALL_COMPILE_METADATA_CONFIGURATION_NAME),
|
||||
project.configurations.getByName(compilation.defaultSourceSet.metadataLibrariesConfigurationName),
|
||||
compilation
|
||||
)
|
||||
|
||||
@@ -364,7 +364,6 @@ class KotlinMetadataTargetConfigurator :
|
||||
val granularMetadataTransformation = GranularMetadataTransformation(
|
||||
project = project,
|
||||
kotlinSourceSet = sourceSet,
|
||||
sourceSetRequestedScopes = dependencyScopesToTransform,
|
||||
parentTransformations = lazy {
|
||||
dependsOnClosureWithInterCompilationDependencies(sourceSet).filterIsInstance<DefaultKotlinSourceSet>()
|
||||
.map { it.compileDependenciesTransformationOrFail }
|
||||
@@ -378,21 +377,28 @@ class KotlinMetadataTargetConfigurator :
|
||||
val sourceSetDependencyConfigurationByScope = project.configurations.sourceSetDependencyConfigurationByScope(sourceSet, scope)
|
||||
|
||||
if (isSourceSetPublished) {
|
||||
project.addExtendsFromRelation(
|
||||
sourceSet.metadataLibrariesConfigurationName,
|
||||
sourceSetDependencyConfigurationByScope.name
|
||||
)
|
||||
|
||||
// we need to include dependencies from sourceSetDependencyConfigurationByScope to
|
||||
// ALL_COMPILE_METADATA_CONFIGURATION_NAME so then we can resolve consistently with it
|
||||
// when resolving [sourceSet.metadataLibrariesConfigurationName]
|
||||
project.addExtendsFromRelation(
|
||||
ALL_COMPILE_METADATA_CONFIGURATION_NAME,
|
||||
sourceSetDependencyConfigurationByScope.name
|
||||
)
|
||||
}
|
||||
|
||||
val sourceSetMetadataConfigurationByScope = project.sourceSetMetadataConfigurationByScope(sourceSet, scope)
|
||||
if (sourceSetMetadataConfigurationByScope != null) {
|
||||
granularMetadataTransformation.applyToConfiguration(sourceSetMetadataConfigurationByScope)
|
||||
project.addExtendsFromRelation(
|
||||
sourceSetMetadataConfigurationByScope.name,
|
||||
ALL_COMPILE_METADATA_CONFIGURATION_NAME
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val sourceSetMetadataConfiguration = project.configurations.getByName(sourceSet.metadataLibrariesConfigurationName)
|
||||
// not necessary: because granularMetadataTransformation already created out of this configuration
|
||||
// so there is no real logic to do dependency handling there.
|
||||
// !!!! granularMetadataTransformation.applyToConfiguration(sourceSetMetadataConfiguration)
|
||||
sourceSetMetadataConfiguration.shouldResolveConsistentlyWith(
|
||||
project.configurations.getByName(ALL_COMPILE_METADATA_CONFIGURATION_NAME)
|
||||
)
|
||||
}
|
||||
|
||||
/** Ensure that the [configuration] excludes the dependencies that are classified by this [GranularMetadataTransformation] as
|
||||
|
||||
+1
-1
@@ -18,6 +18,6 @@ import org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet
|
||||
internal fun Project.addIntransitiveMetadataDependencyIfPossible(sourceSet: DefaultKotlinSourceSet, dependency: FileCollection) {
|
||||
val dependencyConfigurationName =
|
||||
if (project.isIntransitiveMetadataConfigurationEnabled) sourceSet.intransitiveMetadataConfigurationName
|
||||
else sourceSet.implementationMetadataConfigurationName
|
||||
else sourceSet.metadataLibrariesConfigurationName
|
||||
project.dependencies.add(dependencyConfigurationName, dependency)
|
||||
}
|
||||
|
||||
+1
-1
@@ -97,7 +97,7 @@ private fun Project.addDependencies(
|
||||
if (isIdeDependency && sourceSet is DefaultKotlinSourceSet) {
|
||||
val metadataConfigurationName =
|
||||
if (project.isIntransitiveMetadataConfigurationEnabled) sourceSet.intransitiveMetadataConfigurationName
|
||||
else sourceSet.implementationMetadataConfigurationName
|
||||
else sourceSet.metadataLibrariesConfigurationName
|
||||
dependencies.add(metadataConfigurationName, libraries)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user