[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.mpp.MetadataDependencyResolution
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.metadataDependencyResolutionsOrEmpty
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet
|
||||
|
||||
internal inline fun <reified T : MetadataDependencyResolution> KotlinSourceSet.resolveMetadata(): List<T> {
|
||||
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 { it.kotlinSourceSets }
|
||||
.toSet()
|
||||
|
||||
internal val GranularMetadataTransformation?.metadataDependencyResolutionsOrEmpty get() = this?.metadataDependencyResolutions ?: emptyList()
|
||||
+7
-11
@@ -118,20 +118,11 @@ abstract class DefaultKotlinSourceSet @Inject constructor(
|
||||
explicitlyAddedCustomSourceFilesExtensions.addAll(extensions)
|
||||
}
|
||||
|
||||
private var _compileDependenciesTransformation: GranularMetadataTransformation? = null
|
||||
|
||||
internal fun setCompileDependenciesTransformation(value: GranularMetadataTransformation) {
|
||||
_compileDependenciesTransformation = value
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns [GranularMetadataTransformation] for all requested compile dependencies
|
||||
* scopes: API, IMPLEMENTATION, COMPILE_ONLY; See [KotlinDependencyScope.compileScopes]
|
||||
*/
|
||||
internal val compileDependenciesTransformation: GranularMetadataTransformation
|
||||
get() = _compileDependenciesTransformation
|
||||
?: error("Accessing Compile Dependencies Transformations is not yet initialised; " +
|
||||
"Check when setCompileDependenciesTransformation is called")
|
||||
internal var compileDependenciesTransformation: GranularMetadataTransformation? = null
|
||||
|
||||
private val _requiresVisibilityOf = mutableSetOf<KotlinSourceSet>()
|
||||
|
||||
@@ -164,7 +155,7 @@ abstract class DefaultKotlinSourceSet @Inject constructor(
|
||||
|
||||
internal fun getDependenciesTransformation(): Iterable<MetadataDependencyTransformation> {
|
||||
val metadataDependencyResolutionByModule =
|
||||
compileDependenciesTransformation.metadataDependencyResolutions
|
||||
compileDependenciesTransformation.metadataDependencyResolutionsOrEmpty
|
||||
.associateBy { ModuleIds.fromComponent(project, it.dependency) }
|
||||
|
||||
return metadataDependencyResolutionByModule.mapNotNull { (groupAndName, resolution) ->
|
||||
@@ -231,3 +222,8 @@ val Iterable<KotlinSourceSet>.withDependsOnClosure: Set<KotlinSourceSet>
|
||||
fun KotlinMultiplatformExtension.findSourceSetsDependingOn(sourceSet: KotlinSourceSet): Set<KotlinSourceSet> {
|
||||
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,
|
||||
parentTransformations = lazy {
|
||||
dependsOnClosureWithInterCompilationDependencies(sourceSet).filterIsInstance<DefaultKotlinSourceSet>()
|
||||
.map { it.compileDependenciesTransformation }
|
||||
.map { it.compileDependenciesTransformationOrFail }
|
||||
}
|
||||
)
|
||||
|
||||
if (sourceSet is DefaultKotlinSourceSet)
|
||||
sourceSet.setCompileDependenciesTransformation(granularMetadataTransformation)
|
||||
sourceSet.compileDependenciesTransformation = granularMetadataTransformation
|
||||
|
||||
dependencyScopesToTransform.forEach { 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.MetadataConsumer.Cli
|
||||
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.utils.filesProvider
|
||||
import java.io.File
|
||||
@@ -51,7 +52,7 @@ private fun Project.createCInteropMetadataDependencyClasspathFromProjectDependen
|
||||
): FileCollection {
|
||||
return filesProvider {
|
||||
sourceSet.compileDependenciesTransformation
|
||||
.metadataDependencyResolutions
|
||||
.metadataDependencyResolutionsOrEmpty
|
||||
.filterIsInstance<ChooseVisibleSourceSets>()
|
||||
.flatMap { chooseVisibleSourceSets ->
|
||||
/* 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.pm20.toKpmModuleIdentifiers
|
||||
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.locateOrRegisterTask
|
||||
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
|
||||
* during execution and/or configuration phase will result in an internal deadlock in Gradle
|
||||
* `DefaultResourceLockCoordinationService.withStateLock`
|
||||
@@ -180,14 +181,14 @@ internal open class CInteropMetadataDependencyTransformationTask @Inject constru
|
||||
@Suppress("unused")
|
||||
@get:Classpath
|
||||
protected val inputArtifactFiles: FileCollection get() = sourceSet
|
||||
.compileDependenciesTransformation
|
||||
.compileDependenciesTransformationOrFail
|
||||
.configurationToResolve
|
||||
.withoutProjectDependencies()
|
||||
|
||||
@get:Internal
|
||||
protected val chooseVisibleSourceSets
|
||||
get() = sourceSet
|
||||
.compileDependenciesTransformation
|
||||
.compileDependenciesTransformationOrFail
|
||||
.metadataDependencyResolutions
|
||||
.filterIsInstance<ChooseVisibleSourceSets>()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user