[Gradle] Introduce isProjectComponentIdentifierInCurrentBuild
KT-58471 Verification Pending
This commit is contained in:
committed by
Space Team
parent
9ead1d84b1
commit
7c47ff0819
-9
@@ -316,15 +316,6 @@ internal class GranularMetadataTransformation(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal val ResolvedComponentResult.currentBuildProjectIdOrNull
|
|
||||||
get(): ProjectComponentIdentifier? {
|
|
||||||
val identifier = id
|
|
||||||
return when {
|
|
||||||
identifier is ProjectComponentIdentifier && identifier.build.isCurrentBuild -> identifier
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private val Project.allProjectsData: Map<String, GranularMetadataTransformation.ProjectData>
|
private val Project.allProjectsData: Map<String, GranularMetadataTransformation.ProjectData>
|
||||||
get() = rootProject
|
get() = rootProject
|
||||||
.extraProperties
|
.extraProperties
|
||||||
|
|||||||
+2
-3
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||||
import org.jetbrains.kotlin.gradle.plugin.sources.internal
|
import org.jetbrains.kotlin.gradle.plugin.sources.internal
|
||||||
import org.jetbrains.kotlin.gradle.utils.filesProvider
|
import org.jetbrains.kotlin.gradle.utils.filesProvider
|
||||||
|
import org.jetbrains.kotlin.gradle.utils.isProjectComponentIdentifierInCurrentBuild
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.applyIf
|
import org.jetbrains.kotlin.utils.addToStdlib.applyIf
|
||||||
|
|
||||||
internal class MetadataDependencyTransformationTaskInputs(
|
internal class MetadataDependencyTransformationTaskInputs(
|
||||||
@@ -81,8 +82,6 @@ internal class MetadataDependencyTransformationTaskInputs(
|
|||||||
|
|
||||||
private fun Configuration.withoutProjectDependencies(): FileCollection {
|
private fun Configuration.withoutProjectDependencies(): FileCollection {
|
||||||
return incoming.artifactView { view ->
|
return incoming.artifactView { view ->
|
||||||
view.componentFilter { componentIdentifier ->
|
view.componentFilter { componentIdentifier -> !componentIdentifier.isProjectComponentIdentifierInCurrentBuild }
|
||||||
componentIdentifier !is ProjectComponentIdentifier || !componentIdentifier.build.isCurrentBuild
|
|
||||||
}
|
|
||||||
}.files
|
}.files
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.PublishedModuleCoordinatesPro
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.ComputedCapability
|
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.ComputedCapability
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.currentBuildId
|
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.currentBuildId
|
||||||
import org.jetbrains.kotlin.gradle.utils.getValue
|
import org.jetbrains.kotlin.gradle.utils.getValue
|
||||||
|
import org.jetbrains.kotlin.gradle.utils.isProjectComponentIdentifierInCurrentBuild
|
||||||
import org.jetbrains.kotlin.project.model.KpmLocalModuleIdentifier
|
import org.jetbrains.kotlin.project.model.KpmLocalModuleIdentifier
|
||||||
import org.jetbrains.kotlin.project.model.KpmMavenModuleIdentifier
|
import org.jetbrains.kotlin.project.model.KpmMavenModuleIdentifier
|
||||||
import org.jetbrains.kotlin.project.model.KpmModuleIdentifier
|
import org.jetbrains.kotlin.project.model.KpmModuleIdentifier
|
||||||
@@ -47,7 +48,7 @@ internal object ModuleIds {
|
|||||||
|
|
||||||
fun fromComponent(thisProject: Project, component: ResolvedComponentResult) =
|
fun fromComponent(thisProject: Project, component: ResolvedComponentResult) =
|
||||||
// If the project component comes from another build, we can't extract anything from it, so just use the module coordinates:
|
// If the project component comes from another build, we can't extract anything from it, so just use the module coordinates:
|
||||||
if ((component.id as? ProjectComponentIdentifier)?.build?.isCurrentBuild == false)
|
if (!component.id.isProjectComponentIdentifierInCurrentBuild)
|
||||||
ModuleDependencyIdentifier(component.moduleVersion?.group ?: "unspecified", component.moduleVersion?.name ?: "unspecified")
|
ModuleDependencyIdentifier(component.moduleVersion?.group ?: "unspecified", component.moduleVersion?.name ?: "unspecified")
|
||||||
else
|
else
|
||||||
fromComponentId(thisProject, component.id)
|
fromComponentId(thisProject, component.id)
|
||||||
|
|||||||
+2
-1
@@ -10,6 +10,7 @@ import org.gradle.api.artifacts.Configuration
|
|||||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull
|
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
||||||
import org.jetbrains.kotlin.gradle.targets.metadata.dependsOnClosureWithInterCompilationDependencies
|
import org.jetbrains.kotlin.gradle.targets.metadata.dependsOnClosureWithInterCompilationDependencies
|
||||||
|
import org.jetbrains.kotlin.gradle.utils.isProjectComponentIdentifierInCurrentBuild
|
||||||
import org.jetbrains.kotlin.tooling.core.extrasNullableLazyProperty
|
import org.jetbrains.kotlin.tooling.core.extrasNullableLazyProperty
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,7 +84,7 @@ private fun Project.applyTransformationToLegacyDependenciesMetadataConfiguration
|
|||||||
configuration.exclude(mapOf("group" to group, "module" to name))
|
configuration.exclude(mapOf("group" to group, "module" to name))
|
||||||
}
|
}
|
||||||
|
|
||||||
requested.filter { it.dependency.currentBuildProjectIdOrNull == null }.forEach {
|
requested.filter { !it.dependency.id.isProjectComponentIdentifierInCurrentBuild }.forEach {
|
||||||
val (group, name) = ModuleIds.fromComponent(project, it.dependency)
|
val (group, name) = ModuleIds.fromComponent(project, it.dependency)
|
||||||
val notation = listOfNotNull(group.orEmpty(), name, it.dependency.moduleVersion?.version).joinToString(":")
|
val notation = listOfNotNull(group.orEmpty(), name, it.dependency.moduleVersion?.version).joinToString(":")
|
||||||
configuration.resolutionStrategy.force(notation)
|
configuration.resolutionStrategy.force(notation)
|
||||||
|
|||||||
+2
-6
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.gradle.tasks.dependsOn
|
|||||||
import org.jetbrains.kotlin.gradle.tasks.locateOrRegisterTask
|
import org.jetbrains.kotlin.gradle.tasks.locateOrRegisterTask
|
||||||
import org.jetbrains.kotlin.gradle.tasks.withType
|
import org.jetbrains.kotlin.gradle.tasks.withType
|
||||||
import org.jetbrains.kotlin.gradle.utils.filesProvider
|
import org.jetbrains.kotlin.gradle.utils.filesProvider
|
||||||
|
import org.jetbrains.kotlin.gradle.utils.isProjectComponentIdentifierInCurrentBuild
|
||||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||||
import org.jetbrains.kotlin.project.model.KpmModuleIdentifier
|
import org.jetbrains.kotlin.project.model.KpmModuleIdentifier
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.applyIf
|
import org.jetbrains.kotlin.utils.addToStdlib.applyIf
|
||||||
@@ -198,12 +199,7 @@ internal open class CInteropMetadataDependencyTransformationTask @Inject constru
|
|||||||
private fun Iterable<MetadataDependencyResolution>.resolutionsToTransform(): List<ChooseVisibleSourceSets> {
|
private fun Iterable<MetadataDependencyResolution>.resolutionsToTransform(): List<ChooseVisibleSourceSets> {
|
||||||
return filterIsInstance<ChooseVisibleSourceSets>()
|
return filterIsInstance<ChooseVisibleSourceSets>()
|
||||||
.applyIf(skipProjectDependencies) {
|
.applyIf(skipProjectDependencies) {
|
||||||
filterNot {
|
filterNot { it.dependency.id.isProjectComponentIdentifierInCurrentBuild }
|
||||||
val dependencyId = it.dependency.id
|
|
||||||
// filter out ProjectDependencies but keep the ones which are coming from included builds
|
|
||||||
// i.e. they are ProjectDependencies but have isCurrentBuild = false
|
|
||||||
dependencyId is ProjectComponentIdentifier && dependencyId.build.isCurrentBuild
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.gradle.utils
|
||||||
|
|
||||||
|
import org.gradle.api.artifacts.component.ComponentIdentifier
|
||||||
|
import org.gradle.api.artifacts.component.ProjectComponentIdentifier
|
||||||
|
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
|
||||||
|
import org.gradle.api.artifacts.result.ResolvedComponentResult
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For composite builds gradle replaces [ModuleComponentIdentifier] with [ProjectComponentIdentifier]
|
||||||
|
* for which [build.isCurrentBuild] is false
|
||||||
|
* Often, these dependencies needs to be handled differently not as usual ProjectDependencies
|
||||||
|
* Since included build *has to* produce their artifacts on which "current build projects" will depend on.
|
||||||
|
*/
|
||||||
|
internal val ComponentIdentifier.isProjectComponentIdentifierInCurrentBuild: Boolean
|
||||||
|
get() = currentBuildProjectIdOrNull != null
|
||||||
|
|
||||||
|
internal val ComponentIdentifier.currentBuildProjectIdOrNull
|
||||||
|
get(): ProjectComponentIdentifier? = when {
|
||||||
|
this is ProjectComponentIdentifier && build.isCurrentBuild -> this
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
|
||||||
|
internal val ResolvedComponentResult.currentBuildProjectIdOrNull get() = id.currentBuildProjectIdOrNull
|
||||||
Reference in New Issue
Block a user