[Gradle] Do not throw exceptions when getDependenciesTransformation...
is called. Some kotlin plugins (for example JS) re-use DefaultKotlinSourceSet class for their source sets. However DefaultKotlinSourceSet has an API that is connected to IDE import particularly `getDependenciesTransformation`. Since Kotlin/JS doesn't support metadata dependencies, and their transformations as well we should lift strong requirement for compileDependenciesTransformation to be set for each source set. Instead, just return empty list of transformations. ^KT-55347 Verification Pending
This commit is contained in:
committed by
Space Team
parent
5347fc235b
commit
96e1ba045c
+2
-1
@@ -7,9 +7,10 @@ package org.jetbrains.kotlin.gradle.plugin.ide.dependencyResolvers
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.MetadataDependencyResolution
|
import org.jetbrains.kotlin.gradle.plugin.mpp.MetadataDependencyResolution
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.metadataDependencyResolutionsOrEmpty
|
||||||
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet
|
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet
|
||||||
|
|
||||||
internal inline fun <reified T : MetadataDependencyResolution> KotlinSourceSet.resolveMetadata(): List<T> {
|
internal inline fun <reified T : MetadataDependencyResolution> KotlinSourceSet.resolveMetadata(): List<T> {
|
||||||
if (this !is DefaultKotlinSourceSet) return emptyList()
|
if (this !is DefaultKotlinSourceSet) return emptyList()
|
||||||
return compileDependenciesTransformation.metadataDependencyResolutions.filterIsInstance<T>()
|
return compileDependenciesTransformation.metadataDependencyResolutionsOrEmpty.filterIsInstance<T>()
|
||||||
}
|
}
|
||||||
|
|||||||
+2
@@ -364,3 +364,5 @@ private val KotlinMultiplatformExtension.platformCompilationSourceSets: Set<Kotl
|
|||||||
.flatMap { target -> target.compilations }
|
.flatMap { target -> target.compilations }
|
||||||
.flatMap { it.kotlinSourceSets }
|
.flatMap { it.kotlinSourceSets }
|
||||||
.toSet()
|
.toSet()
|
||||||
|
|
||||||
|
internal val GranularMetadataTransformation?.metadataDependencyResolutionsOrEmpty get() = this?.metadataDependencyResolutions ?: emptyList()
|
||||||
+7
-11
@@ -118,20 +118,11 @@ abstract class DefaultKotlinSourceSet @Inject constructor(
|
|||||||
explicitlyAddedCustomSourceFilesExtensions.addAll(extensions)
|
explicitlyAddedCustomSourceFilesExtensions.addAll(extensions)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var _compileDependenciesTransformation: GranularMetadataTransformation? = null
|
|
||||||
|
|
||||||
internal fun setCompileDependenciesTransformation(value: GranularMetadataTransformation) {
|
|
||||||
_compileDependenciesTransformation = value
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns [GranularMetadataTransformation] for all requested compile dependencies
|
* Returns [GranularMetadataTransformation] for all requested compile dependencies
|
||||||
* scopes: API, IMPLEMENTATION, COMPILE_ONLY; See [KotlinDependencyScope.compileScopes]
|
* scopes: API, IMPLEMENTATION, COMPILE_ONLY; See [KotlinDependencyScope.compileScopes]
|
||||||
*/
|
*/
|
||||||
internal val compileDependenciesTransformation: GranularMetadataTransformation
|
internal var compileDependenciesTransformation: GranularMetadataTransformation? = null
|
||||||
get() = _compileDependenciesTransformation
|
|
||||||
?: error("Accessing Compile Dependencies Transformations is not yet initialised; " +
|
|
||||||
"Check when setCompileDependenciesTransformation is called")
|
|
||||||
|
|
||||||
private val _requiresVisibilityOf = mutableSetOf<KotlinSourceSet>()
|
private val _requiresVisibilityOf = mutableSetOf<KotlinSourceSet>()
|
||||||
|
|
||||||
@@ -164,7 +155,7 @@ abstract class DefaultKotlinSourceSet @Inject constructor(
|
|||||||
|
|
||||||
internal fun getDependenciesTransformation(): Iterable<MetadataDependencyTransformation> {
|
internal fun getDependenciesTransformation(): Iterable<MetadataDependencyTransformation> {
|
||||||
val metadataDependencyResolutionByModule =
|
val metadataDependencyResolutionByModule =
|
||||||
compileDependenciesTransformation.metadataDependencyResolutions
|
compileDependenciesTransformation.metadataDependencyResolutionsOrEmpty
|
||||||
.associateBy { ModuleIds.fromComponent(project, it.dependency) }
|
.associateBy { ModuleIds.fromComponent(project, it.dependency) }
|
||||||
|
|
||||||
return metadataDependencyResolutionByModule.mapNotNull { (groupAndName, resolution) ->
|
return metadataDependencyResolutionByModule.mapNotNull { (groupAndName, resolution) ->
|
||||||
@@ -231,3 +222,8 @@ val Iterable<KotlinSourceSet>.withDependsOnClosure: Set<KotlinSourceSet>
|
|||||||
fun KotlinMultiplatformExtension.findSourceSetsDependingOn(sourceSet: KotlinSourceSet): Set<KotlinSourceSet> {
|
fun KotlinMultiplatformExtension.findSourceSetsDependingOn(sourceSet: KotlinSourceSet): Set<KotlinSourceSet> {
|
||||||
return sourceSet.closure { seedSourceSet -> sourceSets.filter { otherSourceSet -> seedSourceSet in otherSourceSet.dependsOn } }
|
return sourceSet.closure { seedSourceSet -> sourceSets.filter { otherSourceSet -> seedSourceSet in otherSourceSet.dependsOn } }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal val DefaultKotlinSourceSet.compileDependenciesTransformationOrFail: GranularMetadataTransformation
|
||||||
|
get() = compileDependenciesTransformation
|
||||||
|
?: error("Accessing Compile Dependencies Transformations that is not yet initialised; " +
|
||||||
|
"Check when compileDependenciesTransformation is set")
|
||||||
+2
-2
@@ -367,12 +367,12 @@ class KotlinMetadataTargetConfigurator :
|
|||||||
sourceSetRequestedScopes = dependencyScopesToTransform,
|
sourceSetRequestedScopes = dependencyScopesToTransform,
|
||||||
parentTransformations = lazy {
|
parentTransformations = lazy {
|
||||||
dependsOnClosureWithInterCompilationDependencies(sourceSet).filterIsInstance<DefaultKotlinSourceSet>()
|
dependsOnClosureWithInterCompilationDependencies(sourceSet).filterIsInstance<DefaultKotlinSourceSet>()
|
||||||
.map { it.compileDependenciesTransformation }
|
.map { it.compileDependenciesTransformationOrFail }
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
if (sourceSet is DefaultKotlinSourceSet)
|
if (sourceSet is DefaultKotlinSourceSet)
|
||||||
sourceSet.setCompileDependenciesTransformation(granularMetadataTransformation)
|
sourceSet.compileDependenciesTransformation = granularMetadataTransformation
|
||||||
|
|
||||||
dependencyScopesToTransform.forEach { scope ->
|
dependencyScopesToTransform.forEach { scope ->
|
||||||
val sourceSetDependencyConfigurationByScope = project.configurations.sourceSetDependencyConfigurationByScope(sourceSet, scope)
|
val sourceSetDependencyConfigurationByScope = project.configurations.sourceSetDependencyConfigurationByScope(sourceSet, scope)
|
||||||
|
|||||||
+2
-1
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.MetadataDependencyResolution.Choos
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.MetadataDependencyResolution.ChooseVisibleSourceSets.MetadataProvider.ProjectMetadataProvider
|
import org.jetbrains.kotlin.gradle.plugin.mpp.MetadataDependencyResolution.ChooseVisibleSourceSets.MetadataProvider.ProjectMetadataProvider
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.MetadataDependencyResolution.ChooseVisibleSourceSets.MetadataProvider.ProjectMetadataProvider.MetadataConsumer.Cli
|
import org.jetbrains.kotlin.gradle.plugin.mpp.MetadataDependencyResolution.ChooseVisibleSourceSets.MetadataProvider.ProjectMetadataProvider.MetadataConsumer.Cli
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.MetadataDependencyResolution.ChooseVisibleSourceSets.MetadataProvider.ProjectMetadataProvider.MetadataConsumer.Ide
|
import org.jetbrains.kotlin.gradle.plugin.mpp.MetadataDependencyResolution.ChooseVisibleSourceSets.MetadataProvider.ProjectMetadataProvider.MetadataConsumer.Ide
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.metadataDependencyResolutionsOrEmpty
|
||||||
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet
|
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet
|
||||||
import org.jetbrains.kotlin.gradle.utils.filesProvider
|
import org.jetbrains.kotlin.gradle.utils.filesProvider
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -51,7 +52,7 @@ private fun Project.createCInteropMetadataDependencyClasspathFromProjectDependen
|
|||||||
): FileCollection {
|
): FileCollection {
|
||||||
return filesProvider {
|
return filesProvider {
|
||||||
sourceSet.compileDependenciesTransformation
|
sourceSet.compileDependenciesTransformation
|
||||||
.metadataDependencyResolutions
|
.metadataDependencyResolutionsOrEmpty
|
||||||
.filterIsInstance<ChooseVisibleSourceSets>()
|
.filterIsInstance<ChooseVisibleSourceSets>()
|
||||||
.flatMap { chooseVisibleSourceSets ->
|
.flatMap { chooseVisibleSourceSets ->
|
||||||
/* We only want to access resolutions that provide metadata from dependency projects */
|
/* We only want to access resolutions that provide metadata from dependency projects */
|
||||||
|
|||||||
+4
-3
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.MetadataDependencyResolution.Choos
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.MetadataDependencyResolution.ChooseVisibleSourceSets.MetadataProvider.ProjectMetadataProvider
|
import org.jetbrains.kotlin.gradle.plugin.mpp.MetadataDependencyResolution.ChooseVisibleSourceSets.MetadataProvider.ProjectMetadataProvider
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.toKpmModuleIdentifiers
|
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.toKpmModuleIdentifiers
|
||||||
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet
|
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.sources.compileDependenciesTransformationOrFail
|
||||||
import org.jetbrains.kotlin.gradle.tasks.dependsOn
|
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
|
||||||
@@ -83,7 +84,7 @@ internal fun Project.locateOrRegisterCInteropMetadataDependencyTransformationTas
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The transformation tasks will internally access the lazy [GranularMetadataTransformation.metadataDependencyResolutions] property
|
* The transformation tasks will internally access the lazy [GranularMetadataTransformation.metadataDependencyResolutionsOrEmpty] property
|
||||||
* which internally will potentially resolve dependencies. Having multiple tasks accessing this synchronized lazy property
|
* which internally will potentially resolve dependencies. Having multiple tasks accessing this synchronized lazy property
|
||||||
* during execution and/or configuration phase will result in an internal deadlock in Gradle
|
* during execution and/or configuration phase will result in an internal deadlock in Gradle
|
||||||
* `DefaultResourceLockCoordinationService.withStateLock`
|
* `DefaultResourceLockCoordinationService.withStateLock`
|
||||||
@@ -180,14 +181,14 @@ internal open class CInteropMetadataDependencyTransformationTask @Inject constru
|
|||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
@get:Classpath
|
@get:Classpath
|
||||||
protected val inputArtifactFiles: FileCollection get() = sourceSet
|
protected val inputArtifactFiles: FileCollection get() = sourceSet
|
||||||
.compileDependenciesTransformation
|
.compileDependenciesTransformationOrFail
|
||||||
.configurationToResolve
|
.configurationToResolve
|
||||||
.withoutProjectDependencies()
|
.withoutProjectDependencies()
|
||||||
|
|
||||||
@get:Internal
|
@get:Internal
|
||||||
protected val chooseVisibleSourceSets
|
protected val chooseVisibleSourceSets
|
||||||
get() = sourceSet
|
get() = sourceSet
|
||||||
.compileDependenciesTransformation
|
.compileDependenciesTransformationOrFail
|
||||||
.metadataDependencyResolutions
|
.metadataDependencyResolutions
|
||||||
.filterIsInstance<ChooseVisibleSourceSets>()
|
.filterIsInstance<ChooseVisibleSourceSets>()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user